随笔分类 -  leetcode

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 19 下一页
摘要:参考:团灭股票问题 base问题:188. Best Time to Buy and Sell Stock IV 问题: 股票问题: 给出一组一支股票每日的价格数组。prices[] 每一天的操作可以为:买buy,卖sell,不操作rest 在第二次buy之前,需要离上一次sell隔一天冷静期,求可 阅读全文
posted @ 2020-09-17 17:07 habibah_chang
摘要:参考:团灭股票问题 问题: 股票问题: 给出一组一支股票每日的价格数组。prices[] 每一天的操作可以为:买buy,卖sell,不操作rest 一次交易从buy开始,若限制在K次交易以内,求可获得的最大收益是多少。 解法:DP(动态规划) 1.确定【状态】: 当前的天数:第 i 天 当前经过的交 阅读全文
posted @ 2020-09-13 16:27 habibah_chang
摘要:问题: 给定一组[start, end]表示气球左右边界的气球数组,求最少射多少箭,能将所有气球射爆。 射箭位置X,start<=X<=end,则能射破该气球。 Example: Input: [[10,16], [2,8], [1,6], [7,12]] Output: 2 Explanation 阅读全文
posted @ 2020-09-13 11:01 habibah_chang
摘要:问题: 给定一组[start, end]的区间数组,求其间最少去掉多少个区间,可使得剩下的区间互不重叠。 ⚠️ 注意:[1,2][2,3]这样:前一个区间end=后一个区间start,的两个区间也不重叠。 Example 1: Input: [[1,2],[2,3],[3,4],[1,3]] Out 阅读全文
posted @ 2020-09-13 10:19 habibah_chang
摘要:参考:https://labuladong.gitbook.io/algo/dong-tai-gui-hua-xi-lie/dong-tai-gui-hua-zhi-kmp-zi-fu-pi-pei-suan-fa 问题:实现strstr,求是否为子串,若是,返回子串所在第一个字符的index,否则 阅读全文
posted @ 2020-09-12 14:30 habibah_chang
摘要:问题: 给定一个字符串s,和一个模式串p,求p是否能匹配s 正则表达支持以下两种符号 '.' Matches any single character. '*' Matches zero or more of the preceding element. Note: s could be empty 阅读全文
posted @ 2020-09-10 19:11 habibah_chang
摘要:参考:https://labuladong.gitbook.io/algo/dong-tai-gui-hua-xi-lie/dong-tai-gui-hua-zhi-bo-yi-wen-ti 问题: 给定一堆石子的得分。A和B两个人进行如下游戏, 轮流,从石堆的两边选择一个石子,最终获得得分最大的人 阅读全文
posted @ 2020-09-10 11:42 habibah_chang
摘要:问题: 给定一个字符串,求其中最长回文子序列(子序列不是连续字符串)的长度。 Example 1: Input: "bbbab" Output: 4 One possible longest palindromic subsequence is "bbbb". Example 2: Input: " 阅读全文
posted @ 2020-09-06 16:57 habibah_chang
摘要:问题: 给定两个字符串,求他们的最长公共子序列的长度。 Example 1: Input: text1 = "abcde", text2 = "ace" Output: 3 Explanation: The longest common subsequence is "ace" and its le 阅读全文
posted @ 2020-09-06 15:26 habibah_chang
摘要:参考:https://mp.weixin.qq.com/s/I0yo0XZamm-jMpG-_B3G8g 问题: 给定一组气球藏有的金币数。若戳破一个气球,则可得其相邻两个气球和自己藏有金币之积。 求按一定顺序戳破气球,最终能获得最多金币是多少。 Note: You may imagine nums 阅读全文
posted @ 2020-09-05 17:03 habibah_chang
摘要:参考:https://labuladong.gitbook.io/algo/dong-tai-gui-hua-xi-lie/zhuang-tai-ya-suo-ji-qiao 问题: 给定两个字符串,求出由一个字符串转化为另一个字符串的最短编辑距离。(编辑操作次数) 有以下三种编辑: 插入 删除 替 阅读全文
posted @ 2020-09-05 15:14 habibah_chang
摘要:问题: 给定一组硬币面值coins,和一个总价amount 求用给定面值硬币中,有多少种构成方法能构成总价。 Example 1: Input: amount = 5, coins = [1, 2, 5] Output: 4 Explanation: there are four ways to m 阅读全文
posted @ 2020-08-31 19:26 habibah_chang
摘要:问题: 给定一组非负整数nums,和一个目标数S,求给nums的各个元素添加符号后,使得和为S的可能性有多少? Example 1: Input: nums is [1, 1, 1, 1, 1], S is 3. Output: 5 Explanation: -1+1+1+1+1 = 3 +1-1+ 阅读全文
posted @ 2020-08-29 17:45 habibah_chang
摘要:问题: 给定一组只包含'0' '1' 的字符串,给定两个正整数m和n,问,要使用m个'0' n个'1',能最多构成多少个给出字符串组中的字符串。 Example 1: Input: strs = ["10","0001","111001","1","0"], m = 5, n = 3 Output: 阅读全文
posted @ 2020-08-29 16:43 habibah_chang
摘要:问题: 给定一组数,请问是否将其分为两个数组,使得二者和相等。 Note: Each of the array element will not exceed 100. The array size will not exceed 200. Example 1: Input: [1, 5, 11, 阅读全文
posted @ 2020-08-29 12:06 habibah_chang
摘要:问题: 求给定数组中,最长递增子序列的长度。 Example: Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the l 阅读全文
posted @ 2020-08-28 15:32 habibah_chang
摘要:问题: 给定一组硬币面值coins,和一个总价amount 求最少用多少个硬币能构成总价,若无法构成,返回-1 Example 1: Input: coins = [1, 2, 5], amount = 11 Output: 3 Explanation: 11 = 5 + 5 + 1 Example 阅读全文
posted @ 2020-08-26 19:33 habibah_chang
摘要:问题: 给定K个鸡蛋,测试N层楼。 若鸡蛋在某一层落下后,刚好不摔碎(再上一层则摔碎),那么即检测到该层F为目标层。 问要检测到F层,最少测试次数为多少? 假设提供到F层被检测对象,为最坏结果(在某一层测试后,鸡蛋的碎或不碎状态,由使得测试对象要被测最多次来决定) Example 1: Input: 阅读全文
posted @ 2020-08-24 17:17 habibah_chang
摘要:转自 https://zxi.mytechroad.com/blog/sp/amortized-analysis/ 证明:1+2+4+8+...+n = 2n-1 a1=1,项数k=log2(n)+1 =等比数列求和=a1*(q^n-1)/(q-1) ①:Sn=a1+a2+...+an ②:q*Sn 阅读全文
posted @ 2020-08-18 14:53 habibah_chang
摘要:问题: 在以下构成的Multiplication Table中,找到第K个小的数字。 The Multiplication Table: m=3, n=3 1 2 3 2 4 6 3 6 9 The Multiplication Table: m=4,n=51 2 3 4 52 4 6 8 103 阅读全文
posted @ 2020-08-16 15:56 habibah_chang

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 19 下一页