diff --git a/problems/problems_2844/solution.go b/problems/problems_2844/solution.go index 882d2517..862cc496 100644 --- a/problems/problems_2844/solution.go +++ b/problems/problems_2844/solution.go @@ -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{} { diff --git a/problems/problems_49/solution.go b/problems/problems_49/solution.go index b39ebee1..1dbde3e0 100644 --- a/problems/problems_49/solution.go +++ b/problems/problems_49/solution.go @@ -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{} {