205. Isomorphic Strings(LeetCode)
Posted 无惧风云
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了205. Isomorphic Strings(LeetCode)相关的知识,希望对你有一定的参考价值。
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:
You may assume both s and t have the same length.
1 class Solution { 2 public: 3 vector<vector<int>> fenbu(string s) 4 { 5 vector <vector<int>> vet; 6 char c; 7 for (int i = 0; i < s.size() - 1; i++) 8 { 9 vector<int> vet1; 10 if (s[i] != ‘0‘) 11 { 12 vet1.push_back(i); 13 c = s[i]; 14 s[i] = ‘0‘; 15 for (int j = i + 1; j < s.size(); j++) 16 { 17 if (s[j] == c) 18 { 19 vet1.push_back(j); 20 s[j] = ‘0‘; 21 } 22 else 23 { 24 if (j == s.size() - 1 && i == s.size() - 2) 25 { 26 vet.push_back(vet1); 27 vet1.clear(); 28 vet1.push_back(j); 29 } 30 } 31 } 32 vet.push_back(vet1); 33 34 } 35 } 36 return vet; 37 } 38 bool isIsomorphic(string s, string t) { 39 if(s.size()==0&&t.size()==0) 40 return true; 41 vector<vector<int>> vet2; 42 vector<vector<int>> vet3; 43 vet2 = fenbu(s); 44 vet3 = fenbu(t); 45 if (vet3 == vet2) 46 return true; 47 else 48 return false; 49 } 50 };
以上是关于205. Isomorphic Strings(LeetCode)的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode 205. Isomorphic Strings
[LeetCode] 205 Isomorphic Strings