LeetCode *** 205. Isomorphic Strings
2016-04-09 23:59
525 查看
题目:
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
Given
Given
Note:
You may assume both s and t have the same length.
分析:
用数字来代表是否规律一致即可。
代码:
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.
分析:
用数字来代表是否规律一致即可。
代码:
class Solution { public: bool isIsomorphic(string s, string t) { int sAscii[95]={}; int sRes=0,sI=1; int tAscii[95]={}; int tRes=0,tI=1; for(int i=0;i<s.length();++i){ if(!sAscii[s[i]-' ']){ sAscii[s[i]-' ']=sI; sI++; sRes=sRes*10+sI; } else sRes=sRes*10+sAscii[s[i]-' ']; if(!tAscii[t[i]-' ']){ tAscii[t[i]-' ']=tI; tI++; tRes=tRes*10+tI; } else tRes=tRes*10+tAscii[t[i]-' ']; } return sRes==tRes; } };
相关文章推荐
- android txt文件的读写总结
- C++之容器(关联容器)
- Jmeter安装和使用
- 爬虫 提取贴吧楼主发布的内容 beatifulsoup和正则配合
- servlet 学习(一)
- 第六周作业
- 通配符的匹配很全面, 但无法找到元素 'amq:broker' 的声明。
- Android程序 类QQ通知常驻在Notification栏 点击Notification正确回调到之前已经放置在后台的Task中的对应Activity,而不是创建它的一个新实例
- 第一章 熟悉Objective-C
- java折半查找算法
- 关于ListView和ScrollView冲突问题的解决方案
- PHP 对目录的操作
- [置顶] merge k sorted lists
- NY1239 引水工程
- 在Android value中添加颜色resource文件
- windows客户端开发--改变visual studio配色方案
- 杭电ACM题1007
- Android 播放视频(四)VideoView全屏视频播放
- windows客户端开发--改变visual studio配色方案
- JDBC+MYSQL初始学习