# Easy-题目46：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 “foo”, “bar”, return false.
Given “paper”, “title”, return true.
Note:
You may assume both s and t have the same length..

public class Solution {
public boolean isIsomorphic(String s, String t) {
int slen=s.length();
int tlen=t.length();
if(slen!=tlen)
return false;
else
{
HashMap<Character,Character> map=new HashMap();
for(int i=0;i<slen;i++)
{
if(!map.containsKey(s.charAt(i)))
map.put(s.charAt(i),t.charAt(i));
else
{
if(map.get(s.charAt(i)) != t.charAt(i))
return false;
}
}
map.clear();
for(int i=0;i<slen;i++)
{
if(!map.containsKey(t.charAt(i)))
map.put(t.charAt(i),s.charAt(i));
else
{
if(map.get(t.charAt(i)) != s.charAt(i))
return false;
}
}
return true;
}
}
}

34ms,beats 30.09%,众数26ms，8.93%

• 本文已收录于以下专栏：

举报原因： 您举报文章：Easy-题目46：205. Isomorphic Strings 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)