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 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两个数组变形记,是否符合规则的更多相关文章
- 205. Isomorphic Strings - LeetCode
Question 205. Isomorphic Strings Solution 题目大意:判断两个字符串是否具有相同的结构 思路:构造一个map,存储每个字符的差,遍历字符串,判断两个两个字符串中 ...
- [leetcode]205. Isomorphic Strings 同构字符串
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- 【刷题-LeetCode】205. Isomorphic Strings
Isomorphic Strings Given two strings *s* and *t*, determine if they are isomorphic. Two strings are ...
- 【LeetCode】205. Isomorphic Strings
题目: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the c ...
- LeetCode 205 Isomorphic Strings
Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
- Java for LeetCode 205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- 205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Java [Leetcode 205]Isomorphic Strings
题目描述: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...
- [LeetCode] 205. Isomorphic Strings 解题思路 - Java
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
随机推荐
- 项目管理理论与实践(6)——利用Excel制作项目文档的设计技巧
这篇是使用的Excel 2007 进行文档设计,Excel的设计也是一门学问,这里主要介绍一些Excel的设计技巧,后面也会陆续更新该文章. 1. 固定某行某列 首先设计这样的任务管理文档: 现在我想 ...
- C#中的线程(四)高级话题
C#中的线程(四)高级话题 Keywords:C# 线程Source:http://www.albahari.com/threading/Author: Joe AlbahariTranslato ...
- Java NIO阻塞式通信
package com.nio.t; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.By ...
- Codeforces Round #279 (Div. 2)B. Queue(构造法,数组下标的巧用)
这道题不错,思维上不难想到规律,但是如何写出优雅的代码比较考功力. 首先第一个人的序号可以确定,那么接下来所有奇数位的序号就可以一个连一个的确定了.然后a[i].first==0时的a[i].seco ...
- scrapy入门实践1
Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. 这就是整个Scrapy的架构图了: 各部件职能: Scrapy ...
- Catch That Cow(广搜)
个人心得:其实有关搜素或者地图啥的都可以用广搜,但要注意标志物不然会变得很复杂,想这题,忘记了标志,结果内存超时: 将每个动作扔入队列,但要注意如何更简便,更节省时间,空间 Farmer John h ...
- 3.Monkey Script小案例
1.实现打开搜狗搜索APP,在搜索框输入内容,点击回车,重复2次运行 2.实现代码如下所示: type=user count=10 speed=1.0 start data >> Laun ...
- mysql的备份恢复等操作
备份数据库 shell> mysqldump -h host -u root -p dbname >dbname_backup.sql 恢复数据库 shell> mysqladmin ...
- IPv4 forwarding is disabled. Networking will not work.
centos 7 docker 启动了一个web服务 但是启动时 报 WARNING: IPv4 forwarding is disabled. Networking will not work. 网 ...
- 用Unreal Engine绘制实时CG影像
转自:http://www.unrealchina.net/portal.php?mod=view&aid=225 近年来,对实时CG的关心热度越来越高,但要想弥补与预渲染方式的差异并不是那么 ...