Skip to content

Commit bbd6430

Browse files
authored
docs: add a description of the solution to lc problem: No.0290 (doocs#765)
No.0290.Word Pattern
1 parent c9108b8 commit bbd6430

File tree

1 file changed

+16
-0
lines changed
  • solution/0200-0299/0290.Word Pattern

1 file changed

+16
-0
lines changed

solution/0200-0299/0290.Word Pattern/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@
4747

4848
<!-- 这里可写通用的实现逻辑 -->
4949

50+
**朴素解法:**
51+
52+
给对应的字符打上印记,使用该字符首次出现的索引位置作为印记值,使用哈希表记录。
53+
54+
而后,将字符串转换为对应的索引数组,如 `pattern = "abbac"`,转换后为 `[0, 1, 1, 0, 4]`。对于字符串 `s` 同理。
55+
56+
> 需注意,`pattern``char``key`;而 `s` 则是以 `' '` 作为分割符,转换为字符串数组之后,以成员 `String``key`
57+
58+
对比两个索引数组,在所有成员一一对应的情况下,才能表示两者规律一致。
59+
60+
优化:
61+
62+
转换为索引数组方便理解,但是太浪费。
63+
64+
可以选择再次遍历字符串,以 `key` 取值对比即可。
65+
5066
<!-- tabs:start -->
5167

5268
### **Python3**

0 commit comments

Comments
 (0)