摘要: https://leetcode.cn/problems/palindrome-partitioning-ii/ # dp[i] 表示 s[0..i] 切分为回文子串的最小分割次数 # dp[i] = min(dp[j] + 1) , 如果 s[j+1...i]是回文串, j < i # dp[i] 阅读全文
posted @ 2022-11-06 20:20 7aughing 阅读(9) 评论(0) 推荐(0) 编辑
摘要: https://leetcode.cn/problems/flip-string-to-monotone-increasing/ def minFlipsMonoIncr(self, s: str) -> int: # n0: 统计当前字符的右边还有多少个0需要被置为1 # n1: 统计当前字符的左 阅读全文
posted @ 2022-11-06 19:35 7aughing 阅读(16) 评论(0) 推荐(0) 编辑
摘要: https://leetcode.cn/problems/find-the-duplicate-number/submissions/ 方法1:pos记录无重复区间的下一个位置 (TLE) def findDuplicate(self, nums: List[int]) -> int: pos = 阅读全文
posted @ 2022-11-06 13:45 7aughing 阅读(12) 评论(0) 推荐(0) 编辑
摘要: https://leetcode.cn/problems/implement-queue-using-stacks/ push: 直接插入辅助栈 pop/peak: 1.如果数据栈有数据,直接出栈; 2.1.否则,如果辅助栈有数据,不停出栈给到数据栈 2.2.出栈数据栈中的元素 class MyQu 阅读全文
posted @ 2022-11-06 11:15 7aughing 阅读(3) 评论(0) 推荐(0) 编辑