码迷,mamicode.com
首页 > 其他好文 > 详细

205. Isomorphic Strings(LeetCode)

时间:2017-07-04 12:14:52      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:else   rmi   tor   elf   and   nbsp   cto   solution   false   

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)

标签:else   rmi   tor   elf   and   nbsp   cto   solution   false   

原文地址:http://www.cnblogs.com/wujufengyun/p/7115838.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!