Skip to content

Commit 8fcd768

Browse files
Merge pull request #58 from chandra9302/patch-5
Create 49-Group-Anagrams.swift
2 parents d14017a + 390349e commit 8fcd768

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

swift/49-Group-Anagrams.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Question Link: https://leetcode.com/problems/anagrams/
3+
*/
4+
5+
class GroupAnagrams {
6+
func groupAnagrams(_ strs: [String]) -> [[String]] {
7+
var ans = [[Int]:[String]]()
8+
let a = "a" as Character
9+
10+
for s in strs {
11+
var count = [Int](repeating: 0, count: 26)
12+
for c in Array(s) {
13+
count[Int(c.asciiValue! - a.asciiValue!)] += 1
14+
}
15+
ans[count, default: []].append(s)
16+
}
17+
return Array(ans.values)
18+
}
19+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy