- 博客(7)
- 收藏
- 关注
原创 [LeetCode][Go] Daily Challenge 2020-11-08 Binary Tree Tilt
/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */import "math"func findTilt(root *TreeNode) int { sum := 0; dfs(root, &sum) return sum}func dfs(nod
2020-11-09 02:45:02
143
原创 [LeetCode][Go] Daily Challenge 2020-11-06 Find the Smallest Divisor Given a Threshold
Find the Smallest Divisor Given a ThresholdGiven an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. Find the smallest divisor such that the resul
2020-11-07 11:12:28
163
原创 [LeetCode][Go] LeetCode 1405. Longest Happy String
func longestDiverseString(a int, b int, c int) string { if a >= b && a >= c { return helper("a", "b", "c", a, b, c) } else if b >= a && b >= c { return helper("b", "a", "c", b, a, c) } else {
2020-05-19 14:52:46
276
原创 [LeetCode][Go] LeetCode 1404. Number of Steps to Reduce a Number in Binary Representation to One
func numSteps(s string) int { cnt, carrier := 0, 0 for i := len(s) - 1; i > 0; i -= 1 { if s[i] == '0' && carrier == 0 { cnt += 1 } else if s[i] == '1' && carrier == 1 { cnt += 1
2020-05-14 09:51:58
226
原创 [LeetCode][Go] LeetCode 1403. Minimum Subsequence in Non-Increasing Order
func minSubsequence(nums []int) []int { sum, sum2 := 0, 0 for _, n := range nums { sum += n } sort.Slice(nums, func(a, b int) bool {return nums[b] < nums[a]}) i := 0 for i < len(nums) && sum2 <= su
2020-05-12 11:25:55
273
原创 [LeetCode][Go] Leetcode 1402. Reducing Dishes
func maxSatisfaction(s []int) int { sort.Ints(s) sum := 0 max := 0 total := 0 for i := len(s) - 1; i >= 0; i-- { sum += s[i] total += sum if(total > max){ max = total } else {
2020-05-11 12:29:08
232
原创 [LeetCode][Go] Leetcode 1401. Circle and Rectangle Overlapping
func checkOverlap(r, x, y, x1, y1, x2, y2 int) bool { if x >= x1 && x <= x2 && y >= y1 && y <= y2 { return true } else if x >= x1 && x <= x2 && (y < y1 || y > y2) { if
2020-05-10 15:33:52
298
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅