File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ Run `readme-generator.py`. Here you ≡Go!
28
28
29
29
| Solved | Easy | Medium | Hard |
30
30
| :----: | :--: | :----: | :--: |
31
- | 155 | 85 | 61| 9|
31
+ | 156 | 86 | 61| 9|
32
32
33
33
34
34
## Solutions
@@ -121,6 +121,7 @@ Run `readme-generator.py`. Here you ≡Go!
121
121
| 200| [ Number of Islands] ( https://leetcode.com/problems/number-of-islands ) | Medium| [ Go] ( src/number-of-islands/solution.go ) |
122
122
| 202| [ Happy Number] ( https://leetcode.com/problems/happy-number ) | Easy| [ Go] ( src/happy-number/solution.go ) |
123
123
| 204| [ Count Primes] ( https://leetcode.com/problems/count-primes ) | Easy| [ Go] ( src/count-primes/solution.go ) |
124
+ | 205| [ Isomorphic Strings] ( https://leetcode.com/problems/isomorphic-strings ) | Easy| [ Go] ( src/isomorphic-strings/solution.go ) |
124
125
| 206| [ Reverse Linked List] ( https://leetcode.com/problems/reverse-linked-list ) | Easy| [ Go] ( src/reverse-linked-list/solution.go ) |
125
126
| 215| [ Kth Largest Element in an Array] ( https://leetcode.com/problems/kth-largest-element-in-an-array ) | Medium| [ Go] ( src/kth-largest-element-in-an-array/solution.go ) |
126
127
| 217| [ Contains Duplicate] ( https://leetcode.com/problems/contains-duplicate ) | Easy| [ Go] ( src/contains-duplicate/solution.go ) |
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ func isIsomorphic (s string , t string ) bool {
6
+ if len (s ) != len (t ) {
7
+ return false
8
+ }
9
+ return checkIsomorphic (s , t ) && checkIsomorphic (t , s )
10
+ }
11
+
12
+ func checkIsomorphic (s string , t string ) bool {
13
+ m := make (map [byte ]byte )
14
+ for i := range s {
15
+ if _ , ok := m [s [i ]]; ok {
16
+ if m [s [i ]] != t [i ] {
17
+ return false
18
+ }
19
+ } else {
20
+ m [s [i ]] = t [i ]
21
+ }
22
+ }
23
+ return true
24
+ }
25
+
26
+ func main () {
27
+ s := "ab"
28
+ t := "aa"
29
+ fmt .Println (isIsomorphic (s , t ))
30
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "testing"
4
+
5
+ func Test_checkIsomorphic (t * testing.T ) {
6
+ type args struct {
7
+ s string
8
+ t string
9
+ }
10
+ tests := []struct {
11
+ name string
12
+ args args
13
+ want bool
14
+ }{
15
+ {
16
+ "1" ,
17
+ args {
18
+ s : "title" ,
19
+ t : "paper" ,
20
+ },
21
+ true ,
22
+ },
23
+ }
24
+ for _ , tt := range tests {
25
+ t .Run (tt .name , func (t * testing.T ) {
26
+ if got := checkIsomorphic (tt .args .s , tt .args .t ); got != tt .want {
27
+ t .Errorf ("checkIsomorphic() = %v, want %v" , got , tt .want )
28
+ }
29
+ })
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments