-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0205_Isomorphic_Strings.java
More file actions
31 lines (27 loc) · 924 Bytes
/
0205_Isomorphic_Strings.java
File metadata and controls
31 lines (27 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* 205. Isomorphic Strings
* Problem Link: https://leetcode.com/problems/isomorphic-strings/description/
* Difficulty: Easy
*
* Solution Created by: Muhammad Khuzaima Umair
* LeetCode : https://leetcode.com/mkhuzaima/
* Github : https://github.com/mkhuzaima
* LinkedIn : https://www.linkedin.com/in/mkhuzaima/
*/
class Solution {
public boolean isIsomorphic(String s, String t) {
int[] map = new int[128];
boolean [] alreadyMapped = new boolean[128];
for (int i = 0; i< s.length(); i++) {
// considering 0 is not a valid value of character
if (map[s.charAt(i)] == 0 && !alreadyMapped[t.charAt(i)]) {
map[s.charAt(i)] = t.charAt(i);
alreadyMapped[t.charAt(i)] = true;
}
else if (map[s.charAt(i)] != t.charAt(i)) {
return false;
}
}
return true;
}
}