Skip to content

Commit 1a5a4e7

Browse files
committed
一刷205
1 parent 4027ea0 commit 1a5a4e7

File tree

7 files changed

+74
-9
lines changed

7 files changed

+74
-9
lines changed

README.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,12 +1461,12 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
14611461
|Easy
14621462
|
14631463

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+
|
14701470

14711471
|{counter:codes}
14721472
|{leetcode_base_url}/reverse-linked-list/[206. Reverse Linked List^]

docs/0205-isomorphic-strings.adoc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,36 @@ All occurrences of a character must be replaced with another character while pre
3939

4040
You may assume both *_s _*and *_t _*have the same length.
4141
42+
== 思路分析
4243
44+
image::images/0205-01.png[{image_attr}]
45+
46+
检查是否为一一映射。
4347
4448
[[src-0205]]
49+
[tabs]
50+
====
51+
一刷::
52+
+
53+
--
4554
[{java_src_attr}]
4655
----
4756
include::{sourcedir}/_0205_IsomorphicStrings.java[tag=answer]
4857
----
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%)^]

docs/images/0205-01.png

95.1 KB
Loading

docs/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ include::0202-happy-number.adoc[leveloffset=+1]
484484

485485
include::0204-count-primes.adoc[leveloffset=+1]
486486

487-
// include::0205-isomorphic-strings.adoc[leveloffset=+1]
487+
include::0205-isomorphic-strings.adoc[leveloffset=+1]
488488

489489
include::0206-reverse-linked-list.adoc[leveloffset=+1]
490490

logbook/202406.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@
610610
|{doc_base_url}/0232-implement-queue-using-stacks.adoc[题解]
611611
|❎
612612

613+
|{counter:codes}
614+
|{leetcode_base_url}/isomorphic-strings/[205. Isomorphic Strings^]
615+
|{doc_base_url}/0205-isomorphic-strings.adoc[题解]
616+
|❎哈希映射
617+
613618
|===
614619

615620
截止目前,本轮练习一共完成 {codes} 道题。

src/main/java/com/diguage/algo/leetcode/_0204_CountPrimes.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
* @since 2020-01-10 23:04
2323
*/
2424
public class _0204_CountPrimes {
25-
// tag::answer[]
25+
// tag::answer[]
2626
/**
2727
* Runtime: 163 ms, faster than 25.96% of Java online submissions for Count Primes.
2828
*
2929
* 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
3033
*/
3134
public int countPrimes(int n) {
3235
if (n < 3) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)