摘要: func maxProfit(prices []int) int { var max = 0 for i:=1;i<len(prices);i++{ if prices[i]>prices[i-1]{//只要后一天比前一天有利可图 max += prices[i]-prices[i-1]//就在前一 阅读全文
posted @ 2021-04-09 14:11 pangqianjin 阅读(33) 评论(0) 推荐(0) 编辑
摘要: 动态规划+sort.SearchInts() func lengthOfLIS(nums []int) int { dp := []int{} for _, num := range nums { i := sort.SearchInts(dp, num) //min_index if i == l 阅读全文
posted @ 2021-04-09 13:57 pangqianjin 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 直接遍历链表,使用set做标记位(标记是否已经到达过) /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ type void struct{} fun 阅读全文
posted @ 2021-04-09 12:28 pangqianjin 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 使用切片slice实现 type MinStack struct { stack []int minIndex int length int } /** initialize your data structure here. */ func Constructor() MinStack { ret 阅读全文
posted @ 2021-04-09 10:19 pangqianjin 阅读(30) 评论(0) 推荐(0) 编辑
摘要: func maxProfit(prices []int) int { // 最大利润=第i天卖出-最小买入 var min_input = prices[0]//默认第0天为最小买入 var max_profit = 0//最大利润 for i:=1;i<len(prices);i++{ min_i 阅读全文
posted @ 2021-04-09 08:29 pangqianjin 阅读(32) 评论(0) 推荐(0) 编辑