关闭

leetcode-205 Isomorphic Strings

238人阅读 评论(0) 收藏 举报
分类:

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.

主要考察匹配映射。字符最多256个。
代码:

class Solution {
public:
    bool isIsomorphic(string s, string t) {
        int m[256]={0};
        int n[256]={0};
        int l=s.size();
        for(int i=0; i < l; i++)
        {
            if(m[s[i]] != n[t[i]])
            return false;
            m[s[i]] = n[t[i]] = i+1;
        }
        return true;
    }
};
0
0
查看评论

205. Isomorphic Strings [easy] (Python)

题目链接https://leetcode.com/problems/isomorphic-strings/题目原文 Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic...
  • coder_orz
  • coder_orz
  • 2016-06-15 14:02
  • 2064

【LeetCode-面试算法经典-Java实现】【205-Isomorphic Strings(同构字符串)】

【205-Isomorphic Strings(同构字符串)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】代码下载【https://github.com/Wang-Jun-Chao】原题  Given two strings s and t, determine if the...
  • DERRANTCM
  • DERRANTCM
  • 2015-08-27 06:33
  • 3593

leetcode-205 Isomorphic Strings

同构字符串 很简单的一个思路(刚开始时试着使用一个unordered_map,好像不够用,用两个hash表最好) class Solution { public: bool isIsomorphic(string s, string t) { int len = s.si...
  • sole_cc
  • sole_cc
  • 2015-05-10 21:20
  • 276

[leetcode-205]Isomorphic Strings(java)

问题描述: 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 occu...
  • zdavb
  • zdavb
  • 2015-08-26 19:35
  • 235

【LeetCode-205】Isomorphic Strings(C++)

题目要求:判断两个字符串的模式相同,及用一个字符串中的字符替换相同位置的第二个字符串中的字符,得到的字符串与第一个字符串相同。 解题方法:这道题要求映射唯一,及对于字符串s中的字符,在t中仅有一个相同位置的字符与其相对应。同样对于t中的字符,在s中也仅有一个相同位置的字符与其相对应。故用两个map...
  • liujiayu1015
  • liujiayu1015
  • 2016-09-09 22:40
  • 204

leetcode 205: 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 occurr...
  • xudli
  • xudli
  • 2015-04-30 04:54
  • 6988

Leetcode_205_Isomorphic Strings

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46530865 Given two strings s and t, determine if they are iso...
  • pistolove
  • pistolove
  • 2015-06-17 10:27
  • 1504

LeetCode 205:Isomorphic Strings

Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replac...
  • sunao2002002
  • sunao2002002
  • 2015-05-08 23:06
  • 3156

[LeetCode-205] Isomorphic Strings(同构字符串)

Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replac...
  • xy010902100449
  • xy010902100449
  • 2015-11-16 22:32
  • 298

关于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 oc...
  • zsy112371
  • zsy112371
  • 2016-09-07 18:31
  • 351
    个人资料
    • 访问:48676次
    • 积分:1137
    • 等级:
    • 排名:千里之外
    • 原创:68篇
    • 转载:0篇
    • 译文:0篇
    • 评论:4条
    文章分类