Skip to content

Commit 4d91c08

Browse files
committed
Add solution #205
1 parent 8732dde commit 4d91c08

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
202|[Happy Number](./0202-happy-number.js)|Easy|
134134
203|[Remove Linked List Elements](./0203-remove-linked-list-elements.js)|Easy|
135135
204|[Count Primes](./0204-count-primes.js)|Medium|
136+
205|[Isomorphic Strings](./0205-isomorphic-strings.js)|Easy|
136137
206|[Reverse Linked List](./0206-reverse-linked-list.js)|Easy|
137138
207|[Course Schedule](./0207-course-schedule.js)|Medium|
138139
213|[House Robber II](./0213-house-robber-ii.js)|Medium|

solutions/0205-isomorphic-strings.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 205. Isomorphic Strings
3+
* https://leetcode.com/problems/isomorphic-strings/
4+
* Difficulty: Easy
5+
*
6+
* Given two strings s and t, determine if they are isomorphic.
7+
*
8+
* Two strings s and t are isomorphic if the characters in s can be replaced to get t.
9+
*
10+
* All occurrences of a character must be replaced with another character while preserving
11+
* the order of characters. No two characters may map to the same character, but a character
12+
* may map to itself.
13+
*/
14+
15+
/**
16+
* @param {string} s
17+
* @param {string} t
18+
* @return {boolean}
19+
*/
20+
var isIsomorphic = function(s, t) {
21+
for (let i = 0; i < s.length; i++) {
22+
if (s.indexOf(s[i], i + 1) !== t.indexOf(t[i], i + 1)) {
23+
return false;
24+
}
25+
}
26+
return true;
27+
};

0 commit comments

Comments
 (0)