[抄题]:

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.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

“对应类问题”:一批标记一次,标记对不上的不行

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

对应类也可以用256,一批标记一次, 标记都是用index i

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

不知道怎么用哈希,但其实256就是哈希的一种。

[关键模板化代码]:

一批标记一次

for (int i = 0; i < n; i++) {
if (m1[s.charAt(i)] != m2[t.charAt(i)]) return false;
m1[s.charAt(i)] = i + 1;
m2[t.charAt(i)] = i + 1;
}

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

290. Word Pattern

[代码风格] :

class Solution {
public boolean isIsomorphic(String s, String t) {
//ini, int[256]
int[] m1 = new int[256];
int[] m2 = new int[256];
int n = s.length(); //judge
for (int i = 0; i < n; i++) {
if (m1[s.charAt(i)] != m2[t.charAt(i)]) return false;
m1[s.charAt(i)] = i + 1;
m2[t.charAt(i)] = i + 1;
} //return false;
return true;
}
}

205. Isomorphic Strings两个数组变形记,是否符合规则的更多相关文章

  1. 205. Isomorphic Strings - LeetCode

    Question 205. Isomorphic Strings Solution 题目大意:判断两个字符串是否具有相同的结构 思路:构造一个map,存储每个字符的差,遍历字符串,判断两个两个字符串中 ...

  2. [leetcode]205. Isomorphic Strings 同构字符串

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  3. 【刷题-LeetCode】205. Isomorphic Strings

    Isomorphic Strings Given two strings *s* and *t*, determine if they are isomorphic. Two strings are ...

  4. 【LeetCode】205. Isomorphic Strings

    题目: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the c ...

  5. LeetCode 205 Isomorphic Strings

    Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...

  6. Java for LeetCode 205 Isomorphic Strings

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  7. 205 Isomorphic Strings

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

  8. Java [Leetcode 205]Isomorphic Strings

    题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...

  9. [LeetCode] 205. Isomorphic Strings 解题思路 - Java

    Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...

随机推荐

  1. mysql 语文成绩大于80,数学成绩大于80

    mysql> select name from test where name = any(select name from test where chengj i > 80 and xu ...

  2. 09-THREE.JS 物体缩放,坐标,旋转,位移,是否可见

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  3. XSLT 教程

    应用自http://www.w3school.com.cn/xsl/index.asp XSL 指扩展样式表语言(EXtensible Stylesheet Language). 万维网联盟开始发展 ...

  4. 团队开发中Git冲突解决

    正常来说我们团队协作开发过程中,冲突是常有的事,下面介绍下本人在开发中的解决办法. 冲突的主要原因就是由于我们开发人员在分支的同一位置写入了不一样的代码,然后合并到主干上导致我们冲突. 方法: 当冲突 ...

  5. Spring通过注解方式实现定时任务

    XML配置: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:/ ...

  6. scrapy入门实践1

    Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. 这就是整个Scrapy的架构图了: 各部件职能: Scrapy ...

  7. 1109. Group Photo (25)

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  8. LeetCode Maximum Distance in Arrays

    原题链接在这里:https://leetcode.com/problems/maximum-distance-in-arrays/description/ 题目: Given m arrays, an ...

  9. 【2】HashMap

    http://www.cnblogs.com/xwdreamer/archive/2012/06/03/2532832.html 一:java的数据结构 在Java编程语言中,最基本的结构就是两种,一 ...

  10. mysql之 double write 浅析

    http://blog.itpub.net/22664653/viewspace-1140915/ 介绍double write之前我们有必要了解partial page write 问题 :     ...