-
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 #909 from 0xff-dev/main
Add solution and test-cases for problem 3039
- Loading branch information
Showing
3 changed files
with
54 additions
and
23 deletions.
There are no files selected for viewing
37 changes: 23 additions & 14 deletions
37
leetcode/3001-3100/3039.Apply-Operations-to-Make-String-Empty/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
27 changes: 25 additions & 2 deletions
27
leetcode/3001-3100/3039.Apply-Operations-to-Make-String-Empty/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,28 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
func Solution(s string) string { | ||
count := [26][2]int{} | ||
mc := 0 | ||
for i, b := range s { | ||
count[b-'a'][0]++ | ||
count[b-'a'][1] = i | ||
mc = max(mc, count[b-'a'][0]) | ||
} | ||
indies := []int{} | ||
for i := 0; i < 26; i++ { | ||
if count[i][0] == mc { | ||
indies = append(indies, count[i][1]) | ||
} | ||
} | ||
sort.Ints(indies) | ||
sb := strings.Builder{} | ||
for _, i := range indies { | ||
sb.WriteByte(s[i]) | ||
} | ||
return sb.String() | ||
} |
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