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

Commit 37f54a6

Browse files
1525_Number_of_Good_Ways_to_Split_a_String
1 parent e85d83c commit 37f54a6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ I have solved quite a number of problems from several topics. See the below tabl
259259
|45| **[157. Read N Characters Given Read4](https://tinyurl.com/y5g49nqt)** | [Python](https://tinyurl.com/wu6rdaw/157_Read_N_Characte_Given_Read4.py), [Swift](https://tinyurl.com/wuja3c4/157_Read_N_Characte_Given_Read4.swift) | --- | Easy (Not So!) | Loved this problem |
260260
|46| **[722. Remove Comments](https://tinyurl.com/y288v3lv)** | [Python](https://tinyurl.com/wu6rdaw/722_Remove_Comments.py), [Swift](https://tinyurl.com/wuja3c4/722_Remove_Comments.swift) | [Art 1](https://tinyurl.com/y56j4p76) | Medium | |
261261
|47| **[443. String Compression](https://tinyurl.com/ybll48vn)** | [Python](https://tinyurl.com/wu6rdaw/443_String_Compression.py), [Swift](https://tinyurl.com/wuja3c4/443_String_Compression.swift) | [Art 1](https://tinyurl.com/y5knbkcd) | Medium | |
262+
|48| **[1525_Number_of_Good_Ways_to_Split_a_String](https://tinyurl.com/yzree7us)** | [Swift](https://tinyurl.com/wuja3c4/1525_Number_of_Good_Ways_to_Split_a_String.swift) | --- | Medium | |
262263

263264

264265
</p>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
func numSplits(_ s: String) -> Int {
3+
guard s.count > 1 else { return 0 }
4+
5+
var (pDict, qDict, gSplitCount) = ([Character:Int](), [Character:Int](), 0)
6+
var stringArray = Array(s)
7+
stringArray.forEach { item in
8+
qDict[item, default: 0] += 1
9+
}
10+
for index in 0..<(stringArray.count - 1) {
11+
pDict[stringArray[index], default: 0] += 1
12+
qDict[stringArray[index], default: 0] -= 1
13+
if qDict[stringArray[index]] == 0 {
14+
qDict.removeValue(forKey:stringArray[index])
15+
}
16+
if pDict.keys.count == qDict.keys.count {
17+
gSplitCount += 1
18+
}
19+
}
20+
return gSplitCount
21+
}
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /