File tree Expand file tree Collapse file tree 7 files changed +74
-9
lines changed
src/main/java/com/diguage/algo/leetcode Expand file tree Collapse file tree 7 files changed +74
-9
lines changed Original file line number Diff line number Diff line change @@ -1461,12 +1461,12 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
1461
1461
|Easy
1462
1462
|
1463
1463
1464
- // |{counter:codes}
1465
- // |{leetcode_base_url}/isomorphic-strings/[205. Isomorphic Strings^]
1466
- // |{source_base_url}/_0205_IsomorphicStrings.java[Java]
1467
- // |{doc_base_url}/0205-isomorphic-strings.adoc[题解]
1468
- // |Easy
1469
- // |
1464
+ |{counter:codes}
1465
+ |{leetcode_base_url}/isomorphic-strings/[205. Isomorphic Strings^]
1466
+ |{source_base_url}/_0205_IsomorphicStrings.java[Java]
1467
+ |{doc_base_url}/0205-isomorphic-strings.adoc[题解]
1468
+ |Easy
1469
+ |
1470
1470
1471
1471
|{counter:codes}
1472
1472
|{leetcode_base_url}/reverse-linked-list/[206. Reverse Linked List^]
Original file line number Diff line number Diff line change @@ -39,11 +39,36 @@ All occurrences of a character must be replaced with another character while pre
39
39
40
40
You may assume both *_s _*and *_t _*have the same length.
41
41
42
+ == 思路分析
42
43
44
+ image::images/0205-01.png[{image_attr}]
45
+
46
+ 检查是否为一一映射。
43
47
44
48
[[src-0205]]
49
+ [tabs]
50
+ ====
51
+ 一刷::
52
+ +
53
+ --
45
54
[{java_src_attr}]
46
55
----
47
56
include::{sourcedir}/_0205_IsomorphicStrings.java[tag=answer]
48
57
----
49
-
58
+ --
59
+
60
+ // 二刷::
61
+ // +
62
+ // --
63
+ // [{java_src_attr}]
64
+ // ----
65
+ // include::{sourcedir}/_0205_IsomorphicStrings_2.java[tag=answer]
66
+ // ----
67
+ // --
68
+ ====
69
+
70
+ == 参考资料
71
+
72
+ . https://leetcode.cn/problems/isomorphic-strings/solutions/536521/tong-gou-zi-fu-chuan-by-leetcode-solutio-s6fd/?envType=study-plan-v2&envId=selected-coding-interview[205. 同构字符串 - 官方题解^]
73
+ . https://leetcode.cn/problems/isomorphic-strings/solutions/1645867/by-jyd-i4wt/?envType=study-plan-v2&envId=selected-coding-interview[205. 同构字符串 - 哈希表,清晰图解^]
74
+ . https://leetcode.cn/problems/isomorphic-strings/solutions/536884/suo-yin-yuan-zu-dan-shuang-ha-xi-biao-5j-mxra/?envType=study-plan-v2&envId=selected-coding-interview[205. 同构字符串 - 索引 + 元组 + 单双哈希表(5解法,超99%)^]
Original file line number Diff line number Diff line change @@ -484,7 +484,7 @@ include::0202-happy-number.adoc[leveloffset=+1]
484
484
485
485
include::0204-count-primes.adoc[leveloffset=+1]
486
486
487
- // include::0205-isomorphic-strings.adoc[leveloffset=+1]
487
+ include::0205-isomorphic-strings.adoc[leveloffset=+1]
488
488
489
489
include::0206-reverse-linked-list.adoc[leveloffset=+1]
490
490
Original file line number Diff line number Diff line change 610
610
|{doc_base_url} /0232-implement-queue-using-stacks.adoc[题解]
611
611
|❎
612
612
613
+ |{counter:codes}
614
+ |{leetcode_base_url} /isomorphic-strings/[205. Isomorphic Strings^]
615
+ |{doc_base_url} /0205-isomorphic-strings.adoc[题解]
616
+ |❎哈希映射
617
+
613
618
|===
614
619
615
620
截止目前,本轮练习一共完成 {codes} 道题。
Original file line number Diff line number Diff line change 22
22
* @since 2020-01-10 23:04
23
23
*/
24
24
public class _0204_CountPrimes {
25
- // tag::answer[]
25
+ // tag::answer[]
26
26
/**
27
27
* Runtime: 163 ms, faster than 25.96% of Java online submissions for Count Primes.
28
28
*
29
29
* Memory Usage: 93.7 MB, less than 5.66% of Java online submissions for Count Primes.
30
+ *
31
+ * @author D瓜哥 · https://www.diguage.com
32
+ * @since 2020-01-10 23:04
30
33
*/
31
34
public int countPrimes (int n ) {
32
35
if (n < 3 ) {
Original file line number Diff line number Diff line change
1
+ package com .diguage .algo .leetcode ;
2
+
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+
6
+ public class _0205_IsomorphicStrings {
7
+ // tag::answer[]
8
+ /**
9
+ * @author D瓜哥 · https://www.diguage.com
10
+ * @since 2024-09-15 22:54:57
11
+ */
12
+ public boolean isIsomorphic (String s , String t ) {
13
+ Map <Character , Character > s2t = new HashMap <>();
14
+ Map <Character , Character > t2s = new HashMap <>();
15
+ for (int i = 0 ; i < s .length (); i ++) {
16
+ char sc = s .charAt (i );
17
+ char tc = t .charAt (i );
18
+ if (s2t .containsKey (sc ) && s2t .get (sc ) != tc ) {
19
+ return false ;
20
+ } else {
21
+ s2t .put (sc , tc );
22
+ }
23
+ if (t2s .containsKey (tc ) && t2s .get (tc ) != sc ) {
24
+ return false ;
25
+ } else {
26
+ t2s .put (tc , sc );
27
+ }
28
+ }
29
+ return true ;
30
+ }
31
+ // end::answer[]
32
+ }
You can’t perform that action at this time.
0 commit comments