Leetcode Isomorphic Strings
来源:互联网 发布:极品飞车ola车数据 编辑:程序博客网 时间:2024/06/09 18:19
Given two strings s and t, determine if they are isomorphic.
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
For example,
Given "egg", "add", return true.
Given "foo", "bar", return false.
Given "paper", "title", return true.
Note:
Two strings are isomorphic if the characters in s can be replaced to get t.
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character but a character may map to itself.
For example,
Given "egg", "add", return true.
Given "foo", "bar", return false.
Given "paper", "title", return true.
Note:
You may assume both s and t have the same length.
这道题是判断两个单词是否同构。这里的同构的意思是,对于例子egg和add,若存在一个映射,e->a,g->d,单词egg和add同构。注意,不可以多个字符映射到同一个字符中去,比如aa和ab。因此对于这种映射,要有两个数组来记录。由于是字符,不会超过256个,因此可以用数组来记录这种映射。
bool isIsomorphic(char* s, char* t) { int l1=strlen(s);int l2=strlen(t);if(l1!=l2)return false;char c[256]={0};char cc[256]={0};for(int i=0;i<l1;i++){if(c[s[i]]==0)c[s[i]]=t[i];else {if(c[s[i]]!=t[i])return false;}if(cc[t[i]]==0)cc[t[i]]=s[i];else if(cc[t[i]]!=s[i])return false;}return true;}
0 0
- LeetCode 205 - Isomorphic Strings
- [LeetCode] Isomorphic Strings
- Isomorphic Strings Leetcode JAVA
- [LeetCode] Isomorphic Strings
- [LeetCode 205]Isomorphic Strings
- LeetCode 205-Isomorphic Strings
- leetcode Isomorphic Strings
- leetcode(c++) Isomorphic Strings
- leetcode--Isomorphic Strings
- [LeetCode]Isomorphic Strings
- LeetCode OJ Isomorphic Strings
- leetcode 205: Isomorphic Strings
- leetcode 205 Isomorphic Strings
- [leetcode] Isomorphic Strings
- 【leetcode】Isomorphic Strings
- [leetcode]Isomorphic Strings
- [LeetCode]Isomorphic Strings
- leetcode--Isomorphic Strings
- 解析xml
- linux 静态库、共享库
- hdu 1556
- Android如何实现程序按下两次返回键退出应用程序?
- C语言面试题
- Leetcode Isomorphic Strings
- 异常处理中的问题
- [UVA12545]Bits Equalizer[贪心]
- 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(一)GIS一张图的系统开发环境以及flexviewer框架
- Longest Common Prefix
- 455A - Boredom
- 关于Javascript变量类型的一些注意点
- 做嵌入式经典网站!(转)
- 乘积最大