-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #852 from 0xff-dev/1525
Add solution and test-cases for problem 1525
- Loading branch information
Showing
3 changed files
with
47 additions
and
23 deletions.
There are no files selected for viewing
32 changes: 18 additions & 14 deletions
32
leetcode/1501-1600/1525.Number-of-Good-Ways-to-Split-a-String/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 23 additions & 2 deletions
25
leetcode/1501-1600/1525.Number-of-Good-Ways-to-Split-a-String/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(s string) int { | ||
ans := 0 | ||
total := [26]int{} | ||
for _, b := range s { | ||
total[b-'a']++ | ||
} | ||
left := [26]int{} | ||
for end := 0; end < len(s)-1; end++ { | ||
left[s[end]-'a']++ | ||
a, b := 0, 0 | ||
for i := 0; i < 26; i++ { | ||
if left[i] > 0 { | ||
a++ | ||
} | ||
if total[i] > left[i] { | ||
b++ | ||
} | ||
} | ||
if a == b { | ||
ans++ | ||
} | ||
} | ||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters