Skip to content

Commit 6bb3873

Browse files
committed
add 737 java
1 parent ffa17a9 commit 6bb3873

File tree

4 files changed

+104
-9
lines changed

4 files changed

+104
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@
975975
711| [Number of Distinct Islands II](https://leetcode.com/problems/number-of-distinct-islands-ii/) | [Python](./leetcode_python/Depth-First-Search/number-of-distinct-islands-ii.py), [Java](./leetcode_java/Depth-First-Search/number-of-distinct-islands-ii.java) | | | Hard |complex, dfs, check `# 200, 694 Number of Distinct Islands`,`amazon`| OK*** (3)
976976
721| [Accounts Merge](https://leetcode.com/problems/accounts-merge/) | [Python ](./leetcode_python/Depth-First-Search/accounts-merge.py) | _O(nlogn)_ | _O(n)_| Medium | dfs, Disjoint Set Union (DSU), `Union Find`,`path compression`, `complex`, `fb`, google, amazon, m$, apple, twitter| AGAIN******* (4) (not start)
977977
733| [Flood Fill](https://leetcode.com/problems/flood-fill/) | [Python](./leetcode_python/Depth-First-Search/flood-fill.py) | _O(m * n)_ | _O(m * n)_ | Easy |`fb`, `amazon`, `good basic`| OK**** (5)
978-
737| [Sentence Similarity II](https://leetcode.com/problems/sentence-similarity-ii/solution/) | [Python](./leetcode_python/Depth-First-Search/sentence-similarity-ii.py) | _O(m * n)_ | _O(m * n)_ | Medium |dfs, union find, `google`|AGAIN**** (2)
978+
737| [Sentence Similarity II](https://leetcode.com/problems/sentence-similarity-ii/solution/) | [Python](./leetcode_python/Depth-First-Search/sentence-similarity-ii.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/DFS/SentenceSimilarity2.java) | _O(m * n)_ | _O(m * n)_ | Medium |dfs, union find, dis-joint, `google`|AGAIN**** (2)
979979
756| [Pyramid Transition Matrix](https://leetcode.com/problems/pyramid-transition-matrix/) | [Python](./leetcode_python/Depth-First-Search/pyramid-transition-matrix.py) | _O(a^b)_ | _O(a^b)_ | Medium || AGAIN (3) (not start)
980980
785| [Is Graph Bipartite?](https://leetcode.com/problems/is-graph-bipartite/) | [Python](./leetcode_python/Depth-First-Search/is-graph-bipartite.py) | _O(\|V\| + \|E\|)_ | _O(\|V\|)_ | Medium |`check #886 Possible Bipartition`,`AGAIN`,`graph`,`dfs`,`fb`, `amazon`| AGAIN*********** (6)
981981
797| [All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target/) | [Python](./leetcode_python/Depth-First-Search/all-paths-from-source-to-target.py) | _O(p + r * n)_ | _O(n)_ | Medium |`graph`, `dfs classics`, `good basic`| AGAIN** (3)

data/progress.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
20241014: 737
12
20241013: 686,734,737
23
20241012: 353
34
20241011: 528,334

data/to_review.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
2024-12-08 -> ['737']
12
2024-12-07 -> ['686,734,737']
23
2024-12-06 -> ['353']
34
2024-12-05 -> ['528,334']
@@ -10,7 +11,7 @@
1011
2024-11-22 -> ['1087']
1112
2024-11-20 -> ['939']
1213
2024-11-18 -> ['430']
13-
2024-11-17 -> ['363']
14+
2024-11-17 -> ['737', '363']
1415
2024-11-16 -> ['686,734,737', '1032,844,1011']
1516
2024-11-15 -> ['353', '947']
1617
2024-11-14 -> ['528,334']
@@ -19,25 +20,25 @@
1920
2024-11-09 -> ['1145,1219']
2021
2024-11-06 -> ['524,221,889']
2122
2024-11-05 -> ['743,889']
22-
2024-11-04 -> ['837', '659']
23+
2024-11-04 -> ['737', '837', '659']
2324
2024-11-03 -> ['686,734,737', '801,552']
2425
2024-11-02 -> ['353', '981', '1057,1066,1110']
2526
2024-11-01 -> ['528,334', '1087']
2627
2024-10-30 -> ['1145', '939']
2728
2024-10-28 -> ['430']
28-
2024-10-27 -> ['1145,1219', '363']
29+
2024-10-27 -> ['737', '1145,1219', '363']
2930
2024-10-26 -> ['686,734,737', '1032,844,1011']
3031
2024-10-25 -> ['353', '947', '1110, 1055']
3132
2024-10-24 -> ['528,334', '524,221,889']
3233
2024-10-23 -> ['743,889']
33-
2024-10-22 -> ['1145', '837', '753']
34+
2024-10-22 -> ['737', '1145', '837', '753']
3435
2024-10-21 -> ['686,734,737', '727']
3536
2024-10-20 -> ['353', '981']
36-
2024-10-19 -> ['528,334', '1145,1219', '1087']
37+
2024-10-19 -> ['737', '528,334', '1145,1219', '1087']
3738
2024-10-18 -> ['686,734,737', '359,1057,1055(todo)']
38-
2024-10-17 -> ['353', '1145', '939']
39-
2024-10-16 -> ['686,734,737', '528,334', '524,221,889']
40-
2024-10-15 -> ['686,734,737', '353', '743,889', '430']
39+
2024-10-17 -> ['737', '353', '1145', '939']
40+
2024-10-16 -> ['737', '686,734,737', '528,334', '524,221,889']
41+
2024-10-15 -> ['737', '686,734,737', '353', '743,889', '430']
4142
2024-10-14 -> ['686,734,737', '353', '528,334', '1145', '1145,1219', '837', '363', '659']
4243
2024-10-13 -> ['353', '528,334', '1032,844,1011', '801,552']
4344
2024-10-12 -> ['528,334', '1145', '981', '947', '1057,1066,1110']

leetcode_java/src/main/java/LeetCodeJava/DFS/SentenceSimilarity2.java

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,97 @@ private int find(int x) {
8282
}
8383

8484
// V2
85+
86+
// V3
87+
// IDEA : Disjoint-set
88+
// https://blog.csdn.net/susuxuezhang/article/details/100127908
89+
// https://www.cnblogs.com/grandyang/p/8053934.html
90+
91+
// V4-1
92+
// IDEA : DFS
93+
// https://zxi.mytechroad.com/blog/hashtable/leetcode-737-sentence-similarity-ii/
94+
// C++
95+
// class Solution {
96+
// public:
97+
// bool areSentencesSimilarTwo(vector<string>& words1, vector<string>& words2, vector<pair<string, string>>& pairs) {
98+
// if (words1.size() != words2.size()) return false;
99+
//
100+
// g_.clear();
101+
//
102+
// for (const auto& p : pairs) {
103+
// g_[p.first].insert(p.second);
104+
// g_[p.second].insert(p.first);
105+
// }
106+
//
107+
// unordered_set<string> visited;
108+
//
109+
// for (int i = 0; i < words1.size(); ++i) {
110+
// visited.clear();
111+
// if (!dfs(words1[i], words2[i], visited)) return false;
112+
// }
113+
//
114+
// return true;
115+
// }
116+
// private:
117+
// bool dfs(const string& src, const string& dst, unordered_set<string>& visited) {
118+
// if (src == dst) return true;
119+
// visited.insert(src);
120+
// for (const auto& next : g_[src]) {
121+
// if (visited.count(next)) continue;
122+
// if (dfs(next, dst, visited)) return true;
123+
// }
124+
// return false;
125+
// }
126+
// unordered_map<string, unordered_set<string>> g_;
127+
// };
128+
129+
130+
// V4-2
131+
// IDEA : Union Find
132+
// https://zxi.mytechroad.com/blog/hashtable/leetcode-737-sentence-similarity-ii/
133+
// C++
134+
// class UnionFindSet {
135+
// public:
136+
// bool Union(const string& word1, const string& word2) {
137+
// const string& p1 = Find(word1, true);
138+
// const string& p2 = Find(word2, true);
139+
// if (p1 == p2) return false;
140+
// parents_[p1] = p2;
141+
// return true;
142+
// }
143+
//
144+
// const string& Find(const string& word, bool create = false) {
145+
// if (!parents_.count(word)) {
146+
// if (!create) return word;
147+
// return parents_[word] = word;
148+
// }
149+
//
150+
// string w = word;
151+
// while (w != parents_[w]) {
152+
// parents_[w] = parents_[parents_[w]];
153+
// w = parents_[w];
154+
// }
155+
//
156+
// return parents_[w];
157+
// }
158+
// private:
159+
// unordered_map<string, string> parents_;
160+
// };
161+
//
162+
// class Solution {
163+
// public:
164+
// bool areSentencesSimilarTwo(vector<string>& words1, vector<string>& words2, vector<pair<string, string>>& pairs) {
165+
// if (words1.size() != words2.size()) return false;
166+
//
167+
// UnionFindSet s;
168+
// for (const auto& pair : pairs)
169+
// s.Union(pair.first, pair.second);
170+
//
171+
// for (int i = 0; i < words1.size(); ++i)
172+
// if (s.Find(words1[i]) != s.Find(words2[i])) return false;
173+
//
174+
// return true;
175+
// }
176+
// };
177+
85178
}

0 commit comments

Comments
 (0)