随笔分类 - leetcode
摘要:/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func zigzagLevelOrder(root *Tree
阅读全文
摘要:func lengthOfLIS(nums []int) int { dp := make([]int, len(nums)) max := 0 for i:=0; i<len(nums); i++ { dp[i] = 1 for j:=0; j<i; j++ { if nums[j] < nums
阅读全文
摘要:func largestNumber(nums []int) string { strList := make([]string, 0, len(nums)) for i := 0; i < len(nums); i++ { strList = append(strList, strconv.Ito
阅读全文
摘要:func threeSum(nums []int) [][]int { // 从小到大排序,如果大于0就不用找了 sort.Ints(nums) res := [][]int{} for i:=0; i<len(nums)-2; i++ { // 结束查找 if nums[i] > 0 { brea
阅读全文
摘要:func maxArea(height []int) int { res := 0 i := 0 j := len(height)-1 for i<j { dif := j-i if height[i]<height[j] { res = max(res, dif * height[i]) i++
阅读全文
摘要:暴力法 func longestConsecutive(nums []int) int { m := map[int]bool{} // 先保存到map for i := 0; i < len(nums); i++ { m[nums[i]] = true } maxLen := 0 for i :=
阅读全文
摘要:/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func levelOrder(root *TreeNode)
阅读全文
摘要:/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func maxDepth(root *TreeNode) in
阅读全文
摘要:func addStrings(num1 string, num2 string) string { sum := "" i := len(num1)-1 j := len(num2)-1 add := 0 for i>=0 || j>=0 || add>0 { x := 0 if i>=0 { x
阅读全文
摘要:/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func isPalindrome(head *ListNode) bool { nums := [
阅读全文
摘要:/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func preorderTraversal(root *Tre
阅读全文
摘要:/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func trainingPlan(head *ListNode, cnt int) *ListNo
阅读全文
摘要:你正在为一家互联网金融公司的风控部门开发一个风险控制系统。该系统需要定期对一些指标进行检查, 例如客户的逾期还款率、 平台的资金流动情况等,以便及时发现并处理风险。 我们已经为您提供了一个名为schedule的调度器类,该类可以用来执行定期的任务。在这个类中, 我们定义了一个start方法用来启动一
阅读全文
摘要:type MyQueue struct { in, out []int } func Constructor() MyQueue { return MyQueue{} } func (this *MyQueue) Push(x int) { this.in = append(this.in, x)
阅读全文
摘要:func search(nums []int, target int) int { left := 0 right := len(nums)-1 for left <= right { mid := (left+right)/2 if target > nums[mid] { left = mid+
阅读全文
摘要:func sortArray(nums []int) []int { quickSort(nums, 0, len(nums)-1) return nums } // 快排,分治的思想,选一个中轴, // 把小于中轴的元素放到左边,大于中轴的元素放到右边 // 然后递归处理中轴两边的元素 func
阅读全文
摘要:/** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func hasCycle(head *ListNode) bool { listMap := ma
阅读全文
摘要:func merge(nums1 []int, m int, nums2 []int, n int) { tail := m+n-1 i := m-1 j := n-1 for i>=0 && j>=0 { if nums1[i] > nums2[j] { nums1[tail] = nums1[i
阅读全文
摘要:func maxProfit(prices []int) int { max := 0 left := 0 for i:=0; i<len(prices); i++ { dif := prices[i]-prices[left] if dif > max { max = dif } if dif <
阅读全文
摘要:package main import "fmt" func isValid(s string) bool { if len(s) <= 1 { return false } chMap := map[byte]byte{ '{': '}', '[': ']', '(': ')', } stack
阅读全文

浙公网安备 33010602011771号