随笔分类 - Leetcode
摘要:复习了一下数位dp 肯定不包含0,但是通常数位dp最后计算的结果较小的是包含前导0的,只是没显示出来而已,所以这题需要前导0,但是非前导0是不需要算进去的,因此,加个是否是前导0的状态即可
阅读全文
摘要:首先回顾一下decode ways I 的做法:链接 分情况讨论 if s[i]=='*' 考虑s[i]单独decode,由于s[i]肯定不会为0,因此我们可以放心的dp+=dp1 再考虑s[i-1]和s[i]decode,如果s[i-1]为*,那么**的组合共有15种(11,12,13.....,
阅读全文
摘要:令dp[i]为从0到i的总方法数,那么很容易得出dp[i]=dp[i-1]+dp[i-2], 即当我们以i为结尾的时候,可以将i单独作为一个字母decode (dp[i-1]),同时也可以将i和i-1作为两个字母组合进行decode. 关键在于出现0的情况,当i-1为0的时候,我们不能将i和i-1进
阅读全文
摘要:3.longest substring Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "
阅读全文
摘要:实习面试前再完成100题,争取能匀速解释清楚题 204. Count Primes 素数筛 1 class Solution { 2 public: 3 int countPrimes(int n) { 4 if(n<=2) return 0; 5 n=n-1; 6 vector<int> prim
阅读全文
摘要:Now, I want to just use English to explain the problem, it's about two month before the interview, so I have to practice my oral English more. And I w
阅读全文
摘要:581. Shortest Unsorted Continuous Subarray Given an integer array, you need to find one continuous subarray that if you only sort this subarray in asc
阅读全文
摘要:5.回文串 几种方法: 暴力:枚举每一个字串,判断是否为回文串,复杂度O(n^3),暴力月莫不可取 dp:区间dp思想,O(n^2) 中心扩展:找每一个字符,然后往两边扩展,O(n^2) manacher算法:主要是中心扩展的一个优化,链接,这篇讲的易懂 6.ZigZag Conversion 之前
阅读全文

浙公网安备 33010602011771号