Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4df5fb5

Browse files
authored
Merge branch 'main' into main
2 parents4f2a683 +edcf7be commit4df5fb5

File tree

361 files changed

+113814
-985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

361 files changed

+113814
-985
lines changed

‎README.md

Lines changed: 488 additions & 488 deletions
Large diffs are not rendered by default.

‎articles/add-two-numbers.md

Lines changed: 587 additions & 0 deletions
Large diffs are not rendered by default.

‎articles/anagram-groups.md

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Solution:
99
for sin strs:
1010
sortedS=''.join(sorted(s))
1111
res[sortedS].append(s)
12-
return res.values()
12+
returnlist(res.values())
1313
```
1414

1515
```java
@@ -85,6 +85,46 @@ public class Solution {
8585
}
8686
```
8787

88+
```go
89+
funcgroupAnagrams(strs []string) [][]string {
90+
res:=make(map[string][]string)
91+
92+
for_,s:=range strs {
93+
sortedS:=sortString(s)
94+
res[sortedS] =append(res[sortedS], s)
95+
}
96+
97+
varresult [][]string
98+
for_,group:=range res {
99+
result =append(result, group)
100+
}
101+
return result
102+
}
103+
104+
funcsortString(sstring)string {
105+
characters:= []rune(s)
106+
sort.Slice(characters,func(i, jint)bool {
107+
return characters[i] < characters[j]
108+
})
109+
returnstring(characters)
110+
}
111+
```
112+
113+
```kotlin
114+
classSolution {
115+
fungroupAnagrams(strs:Array<String>):List<List<String>> {
116+
val res= mutableMapOf<String,MutableList<String>>()
117+
118+
for (sin strs) {
119+
val sortedS= s.toCharArray().sorted().joinToString("")
120+
res.getOrPut(sortedS) {mutableListOf() }.add(s)
121+
}
122+
123+
return res.values.toList()
124+
}
125+
}
126+
```
127+
88128
::tabs-end
89129

90130
###Time & Space Complexity
@@ -109,7 +149,7 @@ class Solution:
109149
for c in s:
110150
count[ord(c) - ord('a')] += 1
111151
res[tuple(count)].append(s)
112-
return res.values()
152+
returnlist(res.values())
113153
```
114154
115155
```java
@@ -199,11 +239,49 @@ public class Solution {
199239
}
200240
```
201241

242+
```go
243+
funcgroupAnagrams(strs []string) [][]string {
244+
res:=make(map[[26]int][]string)
245+
246+
for_,s:=range strs {
247+
varcount [26]int
248+
for_,c:=range s {
249+
count[c-'a']++
250+
}
251+
res[count] =append(res[count], s)
252+
}
253+
254+
varresult [][]string
255+
for_,group:=range res {
256+
result =append(result, group)
257+
}
258+
return result
259+
}
260+
```
261+
262+
```kotlin
263+
classSolution {
264+
fungroupAnagrams(strs:Array<String>):List<List<String>> {
265+
val res=HashMap<List<Int>,MutableList<String>>()
266+
267+
for (sin strs) {
268+
val count=MutableList(26) {0 }
269+
for (cin s) {
270+
count[c-'a']++
271+
}
272+
res.getOrPut(count) {mutableListOf() }.add(s)
273+
}
274+
275+
return res.values.toList()
276+
}
277+
}
278+
```
279+
202280
::tabs-end
203281

204282
###Time & Space Complexity
205283

206284
* Time complexity: $O(m * n)$
207285
* Space complexity: $O(m)$
208286

209-
> Where $m$ is the number of stringsand $n$ is the length of the longest string.
287+
> Where $m$ is the number of stringsand $n$ is the length of the longest string.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp