Skip to content

Commit 699bd43

Browse files
committed
feat: add solutions to lc problem: No.1258
No.1258.Synonymous Sentences
1 parent e7092ae commit 699bd43

File tree

8 files changed

+991
-280
lines changed

8 files changed

+991
-280
lines changed

solution/1200-1299/1257.Smallest Common Region/README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,29 @@ public:
127127
};
128128
```
129129
130-
### **C++**
131-
132-
```cpp
133-
class Solution {
134-
public:
135-
string findSmallestRegion(vector<vector<string>>& regions, string region1, string region2) {
136-
unordered_map<string, string> m;
137-
for (auto& region : regions)
138-
for (int i = 1; i < region.size(); ++i)
139-
m[region[i]] = region[0];
140-
unordered_set<string> s;
141-
while (m.count(region1)) {
142-
s.insert(region1);
143-
region1 = m[region1];
144-
}
145-
while (m.count(region2)) {
146-
if (s.count(region2)) return region2;
147-
region2 = m[region2];
148-
}
149-
return region1;
150-
}
151-
};
130+
### **Go**
131+
132+
```go
133+
func findSmallestRegion(regions [][]string, region1 string, region2 string) string {
134+
m := make(map[string]string)
135+
for _, region := range regions {
136+
for i := 1; i < len(region); i++ {
137+
m[region[i]] = region[0]
138+
}
139+
}
140+
s := make(map[string]bool)
141+
for region1 != "" {
142+
s[region1] = true
143+
region1 = m[region1]
144+
}
145+
for region2 != "" {
146+
if s[region2] {
147+
return region2
148+
}
149+
region2 = m[region2]
150+
}
151+
return region1
152+
}
152153
```
153154

154155
### **...**

solution/1200-1299/1257.Smallest Common Region/README_EN.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,31 @@ public:
124124
};
125125
```
126126
127+
### **Go**
128+
129+
```go
130+
func findSmallestRegion(regions [][]string, region1 string, region2 string) string {
131+
m := make(map[string]string)
132+
for _, region := range regions {
133+
for i := 1; i < len(region); i++ {
134+
m[region[i]] = region[0]
135+
}
136+
}
137+
s := make(map[string]bool)
138+
for region1 != "" {
139+
s[region1] = true
140+
region1 = m[region1]
141+
}
142+
for region2 != "" {
143+
if s[region2] {
144+
return region2
145+
}
146+
region2 = m[region2]
147+
}
148+
return region1
149+
}
150+
```
151+
127152
### **...**
128153

129154
```

0 commit comments

Comments
 (0)