205. Isomorphic Strings
来源:互联网 发布:网络教育专业 编辑:程序博客网 时间:2024/06/06 01:38
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.
public class Solution {
public boolean isIsomorphic(String s, String t) {if (s.length() != t.length()) {
return false;
}
HashMap<Character, Character> hashMapS = new HashMap<Character, Character>();
HashMap<Character, Character> hashMapT = new HashMap<Character, Character>();
for (int i = 0; i < s.length(); i++) {
if (hashMapS.containsKey(s.charAt(i))) {
if (hashMapS.get(s.charAt(i)) != t.charAt(i)) {
return false;
}
} else {
if (hashMapT.containsKey(t.charAt(i))) {
return false;
}
hashMapS.put(s.charAt(i), t.charAt(i));
hashMapT.put(t.charAt(i), s.charAt(i));
}
}
return true;
}
}
0 0
- 205. Isomorphic Strings
- 【LeetCode】205.Isomorphic Strings
- [leetcode] 205.Isomorphic Strings
- LeetCode 205. Isomorphic Strings
- 205. Isomorphic Strings
- 205. Isomorphic Strings LeetCode
- 205. Isomorphic Strings
- 205. Isomorphic Strings
- 205. Isomorphic Strings
- 205. Isomorphic Strings
- 205. Isomorphic Strings
- 205. Isomorphic Strings
- 205. Isomorphic Strings
- 【LeetCode】205. Isomorphic Strings
- LeetCode *** 205. Isomorphic Strings
- leetcode 205. Isomorphic Strings
- LeetCode 205. Isomorphic Strings
- 205. Isomorphic Strings
- django项目cookies和session的常用操作
- SVN的安装和启动
- 流式布局SearchFlowLayout
- 贪心算法学习
- 杭电oj1869 六度分离(folyd)
- 205. Isomorphic Strings
- MongoDB中聚合(aggregate)的使用
- Mushroom的区间 题解
- jq-选择器
- Android7.0 Rild工作流程
- Python的学习笔记DAY12---python和Mysql之二
- js 动态创建forn 并提交数据
- 设计模式
- [Unity3D——用代码说明一切]Unity结合Kinect2体感开发:Kinect面部识别