From 0c73608ce534b066a3db17510e37ad7bbaad1df6 Mon Sep 17 00:00:00 2001 From: kanna5 Date: Mon, 5 Jan 2026 16:48:03 +0900 Subject: [PATCH] add new solutions --- solutions/0/q85/solution.go | 31 ++++++++++++++++++ solutions/10/q1018/solution.go | 15 +++++++++ solutions/12/q1226/solution.go | 20 ++++++++++++ solutions/13/q1304/solution.go | 12 +++++++ solutions/13/q1317/solution.go | 25 +++++++++++++++ solutions/14/q1437/solution.go | 19 +++++++++++ solutions/15/q1518/solution.go | 19 +++++++++++ solutions/15/q1523/solution.go | 13 ++++++++ solutions/17/q1716/solution.go | 16 ++++++++++ solutions/19/q1925/solution.go | 25 +++++++++++++++ solutions/19/q1935/solution.go | 25 +++++++++++++++ solutions/20/q2011/solution.go | 16 ++++++++++ solutions/21/q2154/solution.go | 16 ++++++++++ solutions/21/q2169/solution.go | 15 +++++++++ solutions/22/q2273/solution.go | 37 ++++++++++++++++++++++ solutions/23/q2390/solution.go | 18 +++++++++++ solutions/24/q2405/solution.go | 18 +++++++++++ solutions/30/q3005/solution.go | 27 ++++++++++++++++ solutions/30/q3074/solution.go | 21 ++++++++++++ solutions/31/q3190/solution.go | 13 ++++++++ solutions/32/q3289/solution.go | 19 +++++++++++ solutions/33/q3318/solution.go | 49 ++++++++++++++++++++++++++++ solutions/33/q3349/solution.go | 25 +++++++++++++++ solutions/33/q3354/solution.go | 28 ++++++++++++++++ solutions/33/q3370/solution.go | 12 +++++++ solutions/34/q3432/solution.go | 23 ++++++++++++++ solutions/34/q3461/solution.go | 18 +++++++++++ solutions/35/q3512/solution.go | 11 +++++++ solutions/35/q3516/solution.go | 21 ++++++++++++ solutions/35/q3541/solution.go | 22 +++++++++++++ solutions/36/q3606/solution.go | 58 ++++++++++++++++++++++++++++++++++ solutions/7/q712/solution.go | 31 ++++++++++++++++++ solutions/7/q717/solution.go | 17 ++++++++++ solutions/8/q812/solution.go | 24 ++++++++++++++ solutions/9/q944/solution.go | 16 ++++++++++ solutions/9/q976/solution.go | 16 ++++++++++ 36 files changed, 791 insertions(+) create mode 100644 solutions/0/q85/solution.go create mode 100644 solutions/10/q1018/solution.go create mode 100644 solutions/12/q1226/solution.go create mode 100644 solutions/13/q1304/solution.go create mode 100644 solutions/13/q1317/solution.go create mode 100644 solutions/14/q1437/solution.go create mode 100644 solutions/15/q1518/solution.go create mode 100644 solutions/15/q1523/solution.go create mode 100644 solutions/17/q1716/solution.go create mode 100644 solutions/19/q1925/solution.go create mode 100644 solutions/19/q1935/solution.go create mode 100644 solutions/20/q2011/solution.go create mode 100644 solutions/21/q2154/solution.go create mode 100644 solutions/21/q2169/solution.go create mode 100644 solutions/22/q2273/solution.go create mode 100644 solutions/23/q2390/solution.go create mode 100644 solutions/24/q2405/solution.go create mode 100644 solutions/30/q3005/solution.go create mode 100644 solutions/30/q3074/solution.go create mode 100644 solutions/31/q3190/solution.go create mode 100644 solutions/32/q3289/solution.go create mode 100644 solutions/33/q3318/solution.go create mode 100644 solutions/33/q3349/solution.go create mode 100644 solutions/33/q3354/solution.go create mode 100644 solutions/33/q3370/solution.go create mode 100644 solutions/34/q3432/solution.go create mode 100644 solutions/34/q3461/solution.go create mode 100644 solutions/35/q3512/solution.go create mode 100644 solutions/35/q3516/solution.go create mode 100644 solutions/35/q3541/solution.go create mode 100644 solutions/36/q3606/solution.go create mode 100644 solutions/7/q712/solution.go create mode 100644 solutions/7/q717/solution.go create mode 100644 solutions/8/q812/solution.go create mode 100644 solutions/9/q944/solution.go create mode 100644 solutions/9/q976/solution.go diff --git a/solutions/0/q85/solution.go b/solutions/0/q85/solution.go new file mode 100644 index 0000000..7051fc0 --- /dev/null +++ b/solutions/0/q85/solution.go @@ -0,0 +1,31 @@ +package q85 + +func maximalRectangle(matrix [][]byte) int { + var maxArea int + + for row := range matrix { + for col := range matrix[0] { + matrix[row][col] -= '0' + if matrix[row][col] == 0 { + continue + } + + if col > 0 { + matrix[row][col] += matrix[row][col-1] + } + + maxW := matrix[row][col] + for i := 0; row-i >= 0; i++ { + if matrix[row-i][col] == 0 { + break + } + maxW = min(maxW, matrix[row-i][col]) + maxArea = max(maxArea, int(maxW)*(i+1)) + } + } + } + + return maxArea +} + +var _ = maximalRectangle diff --git a/solutions/10/q1018/solution.go b/solutions/10/q1018/solution.go new file mode 100644 index 0000000..373df41 --- /dev/null +++ b/solutions/10/q1018/solution.go @@ -0,0 +1,15 @@ +package q1018 + +func prefixesDivBy5(nums []int) []bool { + ret := make([]bool, len(nums)) + + num := 0 + for i, n := range nums { + num = num<<1 + n + ret[i] = num%5 == 0 + num %= 5 + } + return ret +} + +var _ = prefixesDivBy5 diff --git a/solutions/12/q1226/solution.go b/solutions/12/q1226/solution.go new file mode 100644 index 0000000..6686b35 --- /dev/null +++ b/solutions/12/q1226/solution.go @@ -0,0 +1,20 @@ +package q1226 + +func abs(i int) int { + if i < 0 { + return -i + } + return i +} + +func minTimeToVisitAllPoints(points [][]int) int { + time := 0 + for i := 0; i < len(points)-1; i++ { + cur, next := points[i], points[i+1] + dx, dy := abs(cur[0]-next[0]), abs(cur[1]-next[1]) + time += max(dx, dy) + } + return time +} + +var _ = minTimeToVisitAllPoints diff --git a/solutions/13/q1304/solution.go b/solutions/13/q1304/solution.go new file mode 100644 index 0000000..ff3c7a1 --- /dev/null +++ b/solutions/13/q1304/solution.go @@ -0,0 +1,12 @@ +package q1304 + +func sumZero(n int) []int { + ret := make([]int, n) + for i := range n / 2 { + ret[i*2] = i + 1 + ret[i*2+1] = -i - 1 + } + return ret +} + +var _ = sumZero diff --git a/solutions/13/q1317/solution.go b/solutions/13/q1317/solution.go new file mode 100644 index 0000000..623b7ba --- /dev/null +++ b/solutions/13/q1317/solution.go @@ -0,0 +1,25 @@ +package q1317 + +func noZero(n int) bool { + for ; n > 0; n /= 10 { + if n%10 == 0 { + return false + } + } + return true +} + +func getNoZeroIntegers(n int) []int { + for i := 1; i <= n/2; i++ { + if !noZero(i) { + continue + } + j := n - i + if noZero(j) { + return []int{i, j} + } + } + return nil +} + +var _ = getNoZeroIntegers diff --git a/solutions/14/q1437/solution.go b/solutions/14/q1437/solution.go new file mode 100644 index 0000000..5db904a --- /dev/null +++ b/solutions/14/q1437/solution.go @@ -0,0 +1,19 @@ +package q1437 + +func kLengthApart(nums []int, k int) bool { + dist := k + + for _, n := range nums { + if n == 0 { + dist++ + } else { + if dist < k { + return false + } + dist = 0 + } + } + return true +} + +var _ = kLengthApart diff --git a/solutions/15/q1518/solution.go b/solutions/15/q1518/solution.go new file mode 100644 index 0000000..62621a7 --- /dev/null +++ b/solutions/15/q1518/solution.go @@ -0,0 +1,19 @@ +package q1518 + +func numWaterBottles(numBottles int, numExchange int) int { + drink := 0 + empty := 0 + for { + drink += numBottles + empty += numBottles + if empty < numExchange { + break + } + + numBottles = empty / numExchange + empty = empty % numExchange + } + return drink +} + +var _ = numWaterBottles diff --git a/solutions/15/q1523/solution.go b/solutions/15/q1523/solution.go new file mode 100644 index 0000000..d1aa683 --- /dev/null +++ b/solutions/15/q1523/solution.go @@ -0,0 +1,13 @@ +package q1523 + +func countOdds(low int, high int) int { + if low%2 == 1 { + low -= 1 + } + if high%2 == 1 { + return (high-low)/2 + 1 + } + return (high - low) / 2 +} + +var _ = countOdds diff --git a/solutions/17/q1716/solution.go b/solutions/17/q1716/solution.go new file mode 100644 index 0000000..b91bfee --- /dev/null +++ b/solutions/17/q1716/solution.go @@ -0,0 +1,16 @@ +package q1716 + +func totalMoney(n int) int { + if n <= 7 { + return (1 + n) * n / 2 + } + base := 28 + + rem := n % 7 + fullWeeks := n / 7 + moneyFW := (base-7)*fullWeeks + 7*(1+fullWeeks)*fullWeeks/2 + moneyRem := (1+rem)*rem/2 + rem*fullWeeks + return moneyFW + moneyRem +} + +var _ = totalMoney diff --git a/solutions/19/q1925/solution.go b/solutions/19/q1925/solution.go new file mode 100644 index 0000000..aab58a4 --- /dev/null +++ b/solutions/19/q1925/solution.go @@ -0,0 +1,25 @@ +package q1925 + +import "math" + +func countTriples(n int) int { + cnt := 0 + for a := 1; a <= n; a++ { + for b := a; b <= n; b++ { + sqC := a*a + b*b + c := int(math.Sqrt(float64(sqC))) + if c > n { + break + } + if c*c == sqC { // c is integer + cnt += 2 + if a == b { + cnt -= 1 + } + } + } + } + return cnt +} + +var _ = countTriples diff --git a/solutions/19/q1935/solution.go b/solutions/19/q1935/solution.go new file mode 100644 index 0000000..4d55c0a --- /dev/null +++ b/solutions/19/q1935/solution.go @@ -0,0 +1,25 @@ +package q1935 + +import "strings" + +func canBeTypedWords(text string, brokenLetters string) int { + var possible = 0 + broken := [26]bool{} + for i := range brokenLetters { + broken[brokenLetters[i]-'a'] = true + } + +Outer: + for _, w := range strings.Fields(text) { + for i := range w { + if broken[w[i]-'a'] { + continue Outer + } + } + possible++ + } + + return possible +} + +var _ = canBeTypedWords diff --git a/solutions/20/q2011/solution.go b/solutions/20/q2011/solution.go new file mode 100644 index 0000000..80cc202 --- /dev/null +++ b/solutions/20/q2011/solution.go @@ -0,0 +1,16 @@ +package q2011 + +func finalValueAfterOperations(operations []string) int { + x := 0 + for i := range operations { + switch operations[i] { + case "X++", "++X": + x++ + case "X--", "--X": + x-- + } + } + return x +} + +var _ = finalValueAfterOperations diff --git a/solutions/21/q2154/solution.go b/solutions/21/q2154/solution.go new file mode 100644 index 0000000..442e7ec --- /dev/null +++ b/solutions/21/q2154/solution.go @@ -0,0 +1,16 @@ +package q2154 + +import "slices" + +func findFinalValue(nums []int, original int) int { + slices.Sort(nums) + + for i := range nums { + if nums[i] == original { + original *= 2 + } + } + return original +} + +var _ = findFinalValue diff --git a/solutions/21/q2169/solution.go b/solutions/21/q2169/solution.go new file mode 100644 index 0000000..4d5cacc --- /dev/null +++ b/solutions/21/q2169/solution.go @@ -0,0 +1,15 @@ +package q2169 + +func countOperations(num1 int, num2 int) int { + cnt := 0 + num1, num2 = max(num1, num2), min(num1, num2) + + for num2 > 0 { + t := num1 % num2 + cnt += num1 / num2 + num1, num2 = num2, t + } + return cnt +} + +var _ = countOperations diff --git a/solutions/22/q2273/solution.go b/solutions/22/q2273/solution.go new file mode 100644 index 0000000..6cd019a --- /dev/null +++ b/solutions/22/q2273/solution.go @@ -0,0 +1,37 @@ +package q2273 + +var buf = [26]int{} +var bufZ = [26]int{} + +func isAnagram(a, b string) bool { + if len(a) != len(b) { + return false + } + seen := buf[:] + copy(seen, bufZ[:]) + for i := range len(a) { + c := a[i] - 'a' + seen[c]++ + } + for i := range len(b) { + c := b[i] - 'a' + seen[c]-- + if seen[c] < 0 { + return false + } + } + return true +} + +func removeAnagrams(words []string) []string { + p := 0 + for i := 1; i < len(words); i++ { + if !isAnagram(words[p], words[i]) { + p++ + words[p] = words[i] + } + } + return words[:p+1] +} + +var _ = removeAnagrams diff --git a/solutions/23/q2390/solution.go b/solutions/23/q2390/solution.go new file mode 100644 index 0000000..44f44ac --- /dev/null +++ b/solutions/23/q2390/solution.go @@ -0,0 +1,18 @@ +package q2390 + +func removeStars(s string) string { + edit := []byte(s) + p := 0 + + for _, c := range edit { + if c == '*' { + p-- + } else { + edit[p] = c + p++ + } + } + return string(edit[:p]) +} + +var _ = removeStars diff --git a/solutions/24/q2405/solution.go b/solutions/24/q2405/solution.go new file mode 100644 index 0000000..64ab052 --- /dev/null +++ b/solutions/24/q2405/solution.go @@ -0,0 +1,18 @@ +package q2405 + +func partitionString(s string) int { + var seen int32 + + partitions := 1 + for i := range len(s) { + offset := s[i] - 'a' + if seen|1< maxFreq { + maxFreq = freq + nMaxFreq = 1 + } else if freq == maxFreq { + nMaxFreq++ + } + freq = 1 + } + } + return maxFreq * nMaxFreq +} + +var _ = maxFrequencyElements diff --git a/solutions/30/q3074/solution.go b/solutions/30/q3074/solution.go new file mode 100644 index 0000000..309877c --- /dev/null +++ b/solutions/30/q3074/solution.go @@ -0,0 +1,21 @@ +package q3074 + +import "slices" + +func minimumBoxes(apple []int, capacity []int) int { + apples := 0 + for _, a := range apple { + apples += a + } + + slices.Sort(capacity) + for i := len(capacity) - 1; i >= 0; i-- { + apples -= capacity[i] + if apples <= 0 { + return len(capacity) - i + } + } + return len(capacity) +} + +var _ = minimumBoxes diff --git a/solutions/31/q3190/solution.go b/solutions/31/q3190/solution.go new file mode 100644 index 0000000..c42a859 --- /dev/null +++ b/solutions/31/q3190/solution.go @@ -0,0 +1,13 @@ +package q3190 + +func minimumOperations(nums []int) int { + nOps := 0 + for _, num := range nums { + if num%3 != 0 { + nOps++ + } + } + return nOps +} + +var _ = minimumOperations diff --git a/solutions/32/q3289/solution.go b/solutions/32/q3289/solution.go new file mode 100644 index 0000000..1bde672 --- /dev/null +++ b/solutions/32/q3289/solution.go @@ -0,0 +1,19 @@ +package q3289 + +func getSneakyNumbers(nums []int) []int { + ret := [2]int{} + p := 0 + + for _, num := range nums { + num %= 1000 + if nums[num] >= 1000 { + ret[p] = num + p++ + } else { + nums[num] += 1000 + } + } + return ret[:] +} + +var _ = getSneakyNumbers diff --git a/solutions/33/q3318/solution.go b/solutions/33/q3318/solution.go new file mode 100644 index 0000000..b9820a6 --- /dev/null +++ b/solutions/33/q3318/solution.go @@ -0,0 +1,49 @@ +package q3318 + +import "slices" + +type NumOccur struct { + num, occur int +} + +func xSum(x int, occurances map[int]int, buf []NumOccur) int { + buf = buf[:] + for n, o := range occurances { + buf = append(buf, NumOccur{n, o}) + } + slices.SortFunc(buf, func(a, b NumOccur) int { + if a.occur != b.occur { + return b.occur - a.occur + } + return b.num - a.num + }) + + sum := 0 + for i := 0; i < x && i < len(buf); i++ { + sum += buf[i].num * buf[i].occur + } + return sum +} + +func findXSum(nums []int, k int, x int) []int { + ret := make([]int, len(nums)-k+1) + + buf := make([]NumOccur, k) + occur := make(map[int]int, k) + for i := range nums { + occur[nums[i]]++ + if i >= k { + occur[nums[i-k]]-- + if occur[nums[i-k]] == 0 { + delete(occur, nums[i-k]) + } + } + if i >= k-1 { + ret[i-k+1] = xSum(x, occur, buf) + } + } + + return ret +} + +var _ = findXSum diff --git a/solutions/33/q3349/solution.go b/solutions/33/q3349/solution.go new file mode 100644 index 0000000..cac3e32 --- /dev/null +++ b/solutions/33/q3349/solution.go @@ -0,0 +1,25 @@ +package q3349 + +func hasIncreasingSubarrays(nums []int, k int) bool { + seqLen := 1 + prevSeqTail := -2 + for i := 1; i < len(nums); i++ { + if nums[i-1] < nums[i] { + seqLen++ + if seqLen == k && prevSeqTail == i-k { + return true + } + if seqLen >= 2*k { + return true + } + } else { + if seqLen >= k { + prevSeqTail = i - 1 + } + seqLen = 1 + } + } + return k == 1 +} + +var _ = hasIncreasingSubarrays diff --git a/solutions/33/q3354/solution.go b/solutions/33/q3354/solution.go new file mode 100644 index 0000000..9a6d784 --- /dev/null +++ b/solutions/33/q3354/solution.go @@ -0,0 +1,28 @@ +package q3354 + +func countValidSelections(nums []int) int { + sumR := 0 + for i := range nums { + sumR += nums[i] + } + + sumL := 0 + nValid := 0 + for i := range nums { + sumR -= nums[i] + if i > 0 { + sumL += nums[i-1] + } + if nums[i] == 0 { + diff := sumL - sumR + if diff == 0 { + nValid += 2 + } else if diff*diff == 1 { + nValid++ + } + } + } + return nValid +} + +var _ = countValidSelections diff --git a/solutions/33/q3370/solution.go b/solutions/33/q3370/solution.go new file mode 100644 index 0000000..3554be8 --- /dev/null +++ b/solutions/33/q3370/solution.go @@ -0,0 +1,12 @@ +package q3370 + +func smallestNumber(n int) int { + i := 0 + for n > 0 { + n >>= 1 + i++ + } + return 1< 2 { + for i := range len(buf) - 1 { + buf[i] = (buf[i] + buf[i+1]) % 10 + } + buf = buf[:len(buf)-1] + } + return buf[0] == buf[1] +} + +var _ = hasSameDigits diff --git a/solutions/35/q3512/solution.go b/solutions/35/q3512/solution.go new file mode 100644 index 0000000..8be2750 --- /dev/null +++ b/solutions/35/q3512/solution.go @@ -0,0 +1,11 @@ +package q3512 + +func minOperations(nums []int, k int) int { + sum := 0 + for i := range nums { + sum += nums[i] + } + return sum % k +} + +var _ = minOperations diff --git a/solutions/35/q3516/solution.go b/solutions/35/q3516/solution.go new file mode 100644 index 0000000..d931850 --- /dev/null +++ b/solutions/35/q3516/solution.go @@ -0,0 +1,21 @@ +package q3516 + +func abs(n int) int { + if n < 0 { + return -n + } + return n +} + +func findClosest(x int, y int, z int) int { + d1, d2 := abs(x-z), abs(y-z) + switch { + case d1 == d2: + return 0 + case d1 < d2: + return 1 + } + return 2 +} + +var _ = findClosest diff --git a/solutions/35/q3541/solution.go b/solutions/35/q3541/solution.go new file mode 100644 index 0000000..fab5b46 --- /dev/null +++ b/solutions/35/q3541/solution.go @@ -0,0 +1,22 @@ +package q3541 + +func maxFreqSum(s string) int { + freqs := [26]int{} + for i := range len(s) { + freqs[s[i]-'a']++ + } + + max1, max2 := 0, 0 + for i, freq := range freqs { + c := byte(i + 'a') + switch c { + case 'a', 'e', 'i', 'o', 'u': + max1 = max(max1, freq) + default: + max2 = max(max2, freq) + } + } + return max1 + max2 +} + +var _ = maxFreqSum diff --git a/solutions/36/q3606/solution.go b/solutions/36/q3606/solution.go new file mode 100644 index 0000000..f251ab2 --- /dev/null +++ b/solutions/36/q3606/solution.go @@ -0,0 +1,58 @@ +package q3606 + +import ( + "slices" + "strings" +) + +func isValidCode(code string) bool { + for i := range len(code) { + c := code[i] + if (c < 'a' || c > 'z') && + (c < 'A' || c > 'Z') && + (c < '0' || c > '9') && + c != '_' { + return false + } + } + return len(code) > 0 +} + +func businessToI(b string) int8 { + switch b { + case "electronics": + return 1 + case "grocery": + return 2 + case "pharmacy": + return 3 + case "restaurant": + return 4 + } + return 0 +} + +func validateCoupons(code []string, businessLine []string, isActive []bool) []string { + validCodes := []int{} + for i := range code { + if isValidCode(code[i]) && businessToI(businessLine[i]) > 0 && isActive[i] { + validCodes = append(validCodes, i) + } + } + + slices.SortFunc(validCodes, func(a, b int) int { + ba, bb := businessToI(businessLine[a]), businessToI(businessLine[b]) + if ba != bb { + return int(ba - bb) + } + return strings.Compare(code[a], code[b]) + }) + + ret := make([]string, 0, len(validCodes)) + for _, i := range validCodes { + ret = append(ret, code[i]) + } + return ret +} + +var _ = validateCoupons diff --git a/solutions/7/q712/solution.go b/solutions/7/q712/solution.go new file mode 100644 index 0000000..31c1a62 --- /dev/null +++ b/solutions/7/q712/solution.go @@ -0,0 +1,31 @@ +package q712 + +func minimumDeleteSum(s1 string, s2 string) int { + mds := make([][]int, len(s1)+1) + for i := range mds { + mds[i] = make([]int, len(s2)+1) + } + + for i := range len(s1) { + mds[i+1][0] = mds[i][0] + int(s1[i]) + } + for i := range len(s2) { + mds[0][i+1] = mds[0][i] + int(s2[i]) + } + + for i1 := 1; i1 <= len(s1); i1++ { + for i2 := 1; i2 <= len(s2); i2++ { + if s1[i1-1] == s2[i2-1] { + mds[i1][i2] = mds[i1-1][i2-1] + } else { + mds[i1][i2] = min( + mds[i1-1][i2]+int(s1[i1-1]), + mds[i1][i2-1]+int(s2[i2-1]), + ) + } + } + } + return mds[len(s1)][len(s2)] +} + +var _ = minimumDeleteSum diff --git a/solutions/7/q717/solution.go b/solutions/7/q717/solution.go new file mode 100644 index 0000000..ba5ad4c --- /dev/null +++ b/solutions/7/q717/solution.go @@ -0,0 +1,17 @@ +package q717 + +func isOneBitCharacter(bits []int) bool { + if len(bits) == 1 { + return true + } + if bits[len(bits)-2] == 0 { + return true + } + cnt1 := 0 + for i := len(bits) - 2; i >= 0 && bits[i] == 1; i-- { + cnt1++ + } + return cnt1%2 == 0 +} + +var _ = isOneBitCharacter diff --git a/solutions/8/q812/solution.go b/solutions/8/q812/solution.go new file mode 100644 index 0000000..fdff97c --- /dev/null +++ b/solutions/8/q812/solution.go @@ -0,0 +1,24 @@ +package q812 + +func area2(a, b []int) float64 { + return float64((a[1]+b[1])*(b[0]-a[0])) / 2 +} + +func largestTriangleArea(points [][]int) float64 { + var maxArea float64 + + for a := 0; a < len(points)-2; a++ { + for b := a + 1; b < len(points)-1; b++ { + for c := b + 1; c < len(points); c++ { + area := area2(points[a], points[b]) + area2(points[b], points[c]) + area2(points[c], points[a]) + if area < 0 { + area = -area + } + maxArea = max(maxArea, area) + } + } + } + return maxArea +} + +var _ = largestTriangleArea diff --git a/solutions/9/q944/solution.go b/solutions/9/q944/solution.go new file mode 100644 index 0000000..ffc9ae4 --- /dev/null +++ b/solutions/9/q944/solution.go @@ -0,0 +1,16 @@ +package q944 + +func minDeletionSize(strs []string) int { + nDel := 0 + for col := range len(strs[0]) { + for row := 1; row < len(strs); row++ { + if strs[row][col] < strs[row-1][col] { + nDel++ + break + } + } + } + return nDel +} + +var _ = minDeletionSize diff --git a/solutions/9/q976/solution.go b/solutions/9/q976/solution.go new file mode 100644 index 0000000..5a2580f --- /dev/null +++ b/solutions/9/q976/solution.go @@ -0,0 +1,16 @@ +package q976 + +import "slices" + +func largestPerimeter(nums []int) int { + slices.Sort(nums) + + for i := len(nums) - 1; i > 1; i-- { + if nums[i-1]+nums[i-2] > nums[i] { + return nums[i] + nums[i-1] + nums[i-2] + } + } + return 0 +} + +var _ = largestPerimeter