LeetCode 205. Isomorphic Strings
来源:互联网 发布:网络摄像机组装配件 编辑:程序博客网 时间:2024/06/09 13:13
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.
分析:
定义两个键值对m1,m2。m1表示s到t的映射,m2表示t到s的映射,如果当前字符已经被映射,并且值不等于
class Solution {public: bool isIsomorphic(string s, string t) { int n=s.length(); map<char,char> m1; map<char,char> m2; cout<<n<<endl; for(int i=0;i<n;i++){ if((m1.count(s[i])>0&& m1[s[i]] != t[i] )||( m2.count(t[i])>0&& m2[t[i]] != s[i])) return false; m1[s[i]]=t[i]; m2[t[i]]=s[i]; } return true; }};
阅读全文
0 0
- 【LeetCode】205.Isomorphic Strings
- [leetcode] 205.Isomorphic Strings
- LeetCode 205. Isomorphic Strings
- 205. Isomorphic Strings LeetCode
- 【LeetCode】205. Isomorphic Strings
- LeetCode *** 205. Isomorphic Strings
- leetcode 205. Isomorphic Strings
- LeetCode 205. Isomorphic Strings
- LeetCode 205. Isomorphic Strings
- leetcode-205. Isomorphic Strings
- LeetCode-205.Isomorphic Strings
- leetcode 205. Isomorphic Strings
- [leetcode] 205. Isomorphic Strings
- 205.[Leetcode]Isomorphic Strings
- leetcode 205. Isomorphic Strings
- 【leetcode】205. Isomorphic Strings
- [Leetcode]205. Isomorphic Strings
- LeetCode - 205. Isomorphic Strings
- 图解HTTPS协议加密解密全过程
- 【牛客】星际穿越
- kubernetes init-container
- UVALive
- POJ
- LeetCode 205. Isomorphic Strings
- 230. Kth Smallest Element in a BST
- Combination Sum
- bzoj 3107: [cqoi2013]二进制a+b 数位dp
- C++实现复数Complex
- 认识HTML5的WebSocket
- Leetcode之Spiral Matrix II 问题
- 【LeetCode算法练习(C++)】Regular Expression Matching
- 习题6-5 巡逻机器人(Patrol Robot, ACM/ICPC Hanoi 2006, UVa1600)