随笔分类 -  算法

摘要:区别: 转载:https://www.cnblogs.com/wpbing/archive/2018/07/26/9370304.html 实现: 树状数组: 转载:https://zhuanlan.zhihu.com/p/77182242 线段树: 转载:https://leetcode-cn.c 阅读全文
posted @ 2020-04-24 22:09 式微胡不归 阅读(184) 评论(0) 推荐(0)
摘要:原文链接:https://leetcode-cn.com/problems/maximum-subarray/solution/xiang-xi-jie-du-dong-tai-gui-hua-de-shi-xian-yi-li/ 通常我们遍历子串或者子序列有三种遍历方式 1. 以某个节点为开头的所 阅读全文
posted @ 2019-11-05 16:14 式微胡不归 阅读(208) 评论(0) 推荐(0)
摘要:题目: https://leetcode-cn.com/problems/decode-ways/ 解码方法 例子:“121013271” 状态方程 (1) 如果S[i] == 0 ① 如果(S[i-1] ==1 || S[i-1] ==2),dp[i]=dp[i-2] “110”->”1,2,1” 阅读全文
posted @ 2019-10-08 15:32 式微胡不归 阅读(238) 评论(0) 推荐(0)
摘要:一. leetcode题目链接 https://leetcode-cn.com/problems/longest-palindromic-subsequence/ 二. 动态规划 (1) 如果一个字符串S[0,1,2,3,,,n-1],S[0] == S[n-1]那么最大回文子序列就是 P(left 阅读全文
posted @ 2019-10-07 21:19 式微胡不归 阅读(279) 评论(0) 推荐(0)
摘要:一. 题目描述: https://leetcode-cn.com/problems/longest-common-subsequence/ 二. 动态规划解法 例如:s1="abcde" s2= "ace",求两个字符串的公共子序列,答案是“ace” 1. S{s1,s2,s3....si} T{t 阅读全文
posted @ 2019-10-07 09:30 式微胡不归 阅读(212) 评论(0) 推荐(0)
摘要:参考答案,特别鸣谢:https://leetcode-cn.com/problems/min-cost-climbing-stairs/solution/scala-dong-tai-gui-hua-di-gui-by-zx233/ 0. 题目描述 数组的每个索引做为一个阶梯,第 i个阶梯对应着一个 阅读全文
posted @ 2019-10-05 10:36 式微胡不归 阅读(285) 评论(0) 推荐(0)
摘要:func sortList(head *ListNode) *ListNode { slist(head,nil) return head } func slist(head *ListNode,tail *ListNode){ if head == nil || head.Next == nil || head == tail{ return } pivot := head.Val i := h 阅读全文
posted @ 2019-09-25 17:15 式微胡不归 阅读(158) 评论(0) 推荐(0)
摘要:一共两个函数 find() 查找根节点 union() 合并两个集合 根据树的高度合并两集合 定义一个rank[]数组,存储两个树的高度,比如rank[xroot] = 3 如果rank[xRoot] > rank{yRoot]的时候,就是x那个树比y那个树要高,所以合并的时候将y那个树的根节点给连 阅读全文
posted @ 2019-09-24 21:36 式微胡不归 阅读(168) 评论(0) 推荐(0)
摘要:func quickSort(nums []int,left int,right int ){ if left < right { p := park(nums,left,right) quickSort(nums,left,p-1) quickSort(nums,p+1,right) } } func park(nums ... 阅读全文
posted @ 2019-09-20 19:12 式微胡不归 阅读(123) 评论(0) 推荐(0)
摘要:解决思路: 1. 栈 2.使用Map,判断是否 匹配 阅读全文
posted @ 2018-01-12 23:20 式微胡不归 阅读(134) 评论(0) 推荐(0)
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文
posted @ 2018-01-10 16:52 式微胡不归 阅读(180) 评论(0) 推荐(0)