Skip to content

Commit ca91302

Browse files
committed
Update (#205)IsomorphicStrings/IsomorphicStrings.java
1 parent 0f7d1ca commit ca91302

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public boolean isIsomorphic(String s, String t) {
3+
if(s.length() != t.length()) return false;
4+
char sc[] = s.toCharArray();
5+
char tc[] = t.toCharArray();
6+
Map<Character, Character> map = new HashMap<Character, Character>();
7+
for(int i = 0; i < sc.length; i++){
8+
if(map.containsKey(sc[i])){
9+
if(map.get(sc[i]) != tc[i])
10+
return false;
11+
else continue;
12+
}
13+
else{
14+
if(map.containsValue(tc[i]))
15+
return false;
16+
else map.put(sc[i], tc[i]);
17+
}
18+
}
19+
return true;
20+
}
21+
}

0 commit comments

Comments
 (0)