zoukankan      html  css  js  c++  java
  • leetcode-Isomorphic Strings

    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 bool isIsomorphic(char* s, char* t) {
     2     if(s == NULL || t == NULL)
     3        return false;
     4     int slen = strlen(s);
     5     int tlen = strlen(t);
     6     if(slen != tlen)
     7       return false;
     8     int index;
     9     int s_char_content[256];
    10     int t_char_content[256];
    11     for(index = 0; index < 256 ;index++)
    12     {
    13         s_char_content[index] = 257;
    14         t_char_content[index] = 257;
    15     }
    16     
    17     for(index = 0; index < slen; index++)
    18     {
    19         if(s_char_content[s[index]] == 257)
    20         {
    21             if(t_char_content[t[index]] == 257)
    22             {
    23                 s_char_content[s[index]] = t[index];
    24                 t_char_content[t[index]] = s[index];
    25             }
    26             else return false;
    27         }
    28         else
    29         {
    30             if(s_char_content[s[index]] != t[index])
    31                return false;
    32         }
    33     }
    34     return true;
    35 }
  • 相关阅读:
    浅拷贝与深拷贝
    省市县三级异步加载导航
    数据处理为树形结构以及多级菜单的逻辑分析
    九宫格
    数组及字符串方法
    定时器
    js,ajax获取数据
    js去重
    js常见排序
    SSH+DWZ、JQuery-UI ,swfobject.embedSWF属性与用法,IE下日期控件被flash控件挡住
  • 原文地址:https://www.cnblogs.com/neyer/p/4504846.html
Copyright © 2011-2022 走看看