Skip to content

Commit

Permalink
test: golang 2844, 49
Browse files Browse the repository at this point in the history
solution
  • Loading branch information
QuBenhao committed Jul 24, 2024
1 parent 45fd62c commit d620dfb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
19 changes: 18 additions & 1 deletion problems/problems_2844/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,24 @@ import (
)

func minimumOperations(num string) int {

n, zero := len(num), false
for i, five := n-1, false; i >= 0; i-- {
c := num[i]
if zero && (c == '0' || c == '5') ||
five && (c == '2' || c == '7') {
return n - i - 2
}
if c == '0' {
zero = true
}
if c == '5' {
five = true
}
}
if zero {
return n - 1
}
return n
}

func Solve(inputJsonValues string) interface{} {
Expand Down
14 changes: 13 additions & 1 deletion problems/problems_49/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ package problem49
import (
"encoding/json"
"log"
"sort"
"strings"
)

func groupAnagrams(strs []string) [][]string {

group := map[string][]string{}
for _, str := range strs {
s := []byte(str)
sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })
sortedStr := string(s)
group[sortedStr] = append(group[sortedStr], str)
}
ans := make([][]string, 0, len(group))
for _, v := range group {
ans = append(ans, v)
}
return ans
}

func Solve(inputJsonValues string) interface{} {
Expand Down

0 comments on commit d620dfb

Please sign in to comment.