• 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 };
  • 相关阅读:
    分分钟用上C#中的委托和事件
    AutoResetEvent详解
    C#跨线程调用
    多线程编程的注意事项
    C#中WinForm程序退出方法技巧总结
    用c#实现单链表(程序代码已经验证,完全正确)
    event & EventHandler
    Kubernetes理论02
    centos7 日志文件
    CentOS7 FTP安装与配置
  • 原文地址:https://www.cnblogs.com/wujufengyun/p/7115838.html
Copyright © 2020-2023  润新知