|
2565 | 2565 | "sort-colors":{
|
2566 | 2566 | "id": "75",
|
2567 | 2567 | "name": "sort-colors",
|
2568 |
| - "pre": [ |
2569 |
| - { |
2570 |
| - "text": "荷兰国旗问题", |
2571 |
| - "link": "https://en.wikipedia.org/wiki/Dutch_national_flag_problem", |
2572 |
| - "color": "purple" |
2573 |
| - }, |
2574 |
| - { |
2575 |
| - "text": "排序", |
2576 |
| - "link": null, |
2577 |
| - "color": "purple" |
2578 |
| - } |
2579 |
| - ], |
2580 |
| - "keyPoints": [ |
2581 |
| - { |
2582 |
| - "text": "荷兰国旗问题", |
2583 |
| - "link": null, |
2584 |
| - "color": "blue" |
2585 |
| - }, |
2586 |
| - { |
2587 |
| - "text": "countingsort", |
2588 |
| - "link": null, |
2589 |
| - "color": "blue" |
2590 |
| - } |
2591 |
| - ], |
2592 |
| - "companies": [ |
2593 |
| - { |
2594 |
| - "name": "阿里巴巴" |
2595 |
| - }, |
2596 |
| - { |
2597 |
| - "name": "腾讯" |
2598 |
| - }, |
2599 |
| - { |
2600 |
| - "name": "百度" |
2601 |
| - }, |
2602 |
| - { |
2603 |
| - "name": "字节跳动" |
2604 |
| - } |
2605 |
| - ], |
| 2568 | + "pre": [], |
| 2569 | + "keyPoints": [], |
| 2570 | + "companies": [], |
2606 | 2571 | "giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/75.sort-colors.md",
|
2607 | 2572 | "solution": "https://github.com/azl397985856/leetcode/blob/master/problems/75.sort-colors.md",
|
2608 |
| - "code": [ |
2609 |
| - { |
2610 |
| - "language": "cpp", |
2611 |
| - "text": "\nclass Solution {\npublic:\n void sortColors(vector<int>& nums) {\n int r = 0, g = 0, b = 0;\n for (int n : nums) {\n if (n == 0) {\n nums[b++] = 2;\n nums[g++] = 1;\n nums[r++] = 0;\n } else if (n == 1) {\n nums[b++] = 2;\n nums[g++] = 1;\n } else nums[b++] = 2;\n }\n }\n};\n" |
2612 |
| - }, |
2613 |
| - { |
2614 |
| - "language": "py", |
2615 |
| - "text": "\nclass Solution:\n def sortColors(self, strs):\n # p0 是右边界\n # p1 是右边界\n # p2 是左边界\n # p1 超过 p2 结束\n p0, p1, p2 = 0, 0, len(strs) - 1\n\n while p1 <= p2:\n if strs[p1] == 'blue':\n strs[p2], strs[p1] = strs[p1], strs[p2]\n p2 -= 1\n elif strs[p1] == 'red':\n strs[p0], strs[p1] = strs[p1], strs[p0]\n p0 += 1\n p1 += 1 # p0 一定不是 blue,因此 p1 += 1\n else: # p1 === 'green'\n p1 += 1\n return strs\n" |
2616 |
| - }, |
2617 |
| - { |
2618 |
| - "language": "py", |
2619 |
| - "text": "\nclass Solution:\n def partition(self, head: ListNode, x: int) -> ListNode:\n l1 = cur = head\n while cur:\n if cur.val < x:\n cur.val, l1.val = l1.val, cur.val\n l1 = l1.next\n cur = cur.next\n return head\n" |
2620 |
| - } |
2621 |
| - ] |
| 2573 | + "code": [] |
2622 | 2574 | },
|
2623 | 2575 | "subsets":{
|
2624 | 2576 | "id": "78",
|
@@ -10730,34 +10682,12 @@
|
10730 | 10682 | "snakes-and-ladders":{
|
10731 | 10683 | "id": "909",
|
10732 | 10684 | "name": "snakes-and-ladders",
|
10733 |
| - "pre": [ |
10734 |
| - { |
10735 |
| - "text": "广度优先遍历", |
10736 |
| - "link": null, |
10737 |
| - "color": "gold" |
10738 |
| - } |
10739 |
| - ], |
10740 |
| - "keyPoints": [ |
10741 |
| - { |
10742 |
| - "text": "根据矩阵编号如何算出其都在的行号和列号。这里其实用到了number=(row", |
10743 |
| - "link": null, |
10744 |
| - "color": "blue" |
10745 |
| - }, |
10746 |
| - { |
10747 |
| - "text": "1)\\*n+col这样的一个公式,后面的所有公式都是基于它产生的。", |
10748 |
| - "link": null, |
10749 |
| - "color": "blue" |
10750 |
| - } |
10751 |
| - ], |
| 10685 | + "pre": [], |
| 10686 | + "keyPoints": [], |
10752 | 10687 | "companies": [],
|
10753 | 10688 | "giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/909.snakes-and-ladders.md",
|
10754 | 10689 | "solution": "https://github.com/azl397985856/leetcode/blob/master/problems/909.snakes-and-ladders.md",
|
10755 |
| - "code": [ |
10756 |
| - { |
10757 |
| - "language": "py", |
10758 |
| - "text": "\n\nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n q = collections.deque([(1, 0)])\n n = len(board)\n visited = set()\n\n def get_pos(pos):\n row = (n - 1) - (pos - 1) // n\n col = (n - 1) - ((pos - 1) % n) if row & 1 == n & 1 else (pos - 1) % n\n return row, col\n\n while q:\n for _ in range(len(q)):\n cur, steps = q.popleft()\n if cur in visited:\n continue\n visited.add(cur)\n if cur == n ** 2:\n return steps\n for nxt in range(cur + 1, min(cur + 6, n * n) + 1):\n row, col = get_pos(nxt)\n if board[row][col] == -1:\n q.append((nxt, steps + 1))\n else:\n q.append((board[row][col], steps + 1))\n return -1\n\n" |
10759 |
| - } |
10760 |
| - ] |
| 10690 | + "code": [] |
10761 | 10691 | },
|
10762 | 10692 | "online-election":{
|
10763 | 10693 | "id": "911",
|
|
14179 | 14109 | }
|
14180 | 14110 | ]
|
14181 | 14111 | },
|
| 14112 | +"count-k-subsequences-of-a-string-with-maximum-beauty":{ |
| 14113 | + "id": "2842", |
| 14114 | + "name": "count-k-subsequences-of-a-string-with-maximum-beauty", |
| 14115 | + "pre": [ |
| 14116 | + { |
| 14117 | + "text": "排列组合", |
| 14118 | + "link": null, |
| 14119 | + "color": "green" |
| 14120 | + } |
| 14121 | + ], |
| 14122 | + "keyPoints": [], |
| 14123 | + "companies": [], |
| 14124 | + "giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/2842.count-k-subsequences-of-a-string-with-maximum-beauty.md", |
| 14125 | + "solution": "https://github.com/azl397985856/leetcode/blob/master/problems/2842.count-k-subsequences-of-a-string-with-maximum-beauty.md", |
| 14126 | + "code": [ |
| 14127 | + { |
| 14128 | + "language": "py", |
| 14129 | + "text": "\nclass Solution:\n def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int:\n MOD = 10 ** 9 + 7\n ans = 1\n cnt = Counter(Counter(s).values())\n for c, num in sorted(cnt.items(), reverse=True):\n # c 是出现次数\n # num 是出现次数为 c 的有多少个\n if num >= k:\n return ans * pow(c, k, MOD) * comb(num, k) % MOD\n ans *= pow(c, num, MOD) * comb(num, num) % MOD\n k -= num\n return 0\n\n" |
| 14130 | + } |
| 14131 | + ] |
| 14132 | +}, |
| 14133 | +"beautiful-towers-ii":{ |
| 14134 | + "id": "2866", |
| 14135 | + "name": "beautiful-towers-ii", |
| 14136 | + "pre": [ |
| 14137 | + { |
| 14138 | + "text": "动态规划", |
| 14139 | + "link": null, |
| 14140 | + "color": "red" |
| 14141 | + }, |
| 14142 | + { |
| 14143 | + "text": "单调栈", |
| 14144 | + "link": null, |
| 14145 | + "color": "purple" |
| 14146 | + } |
| 14147 | + ], |
| 14148 | + "keyPoints": [], |
| 14149 | + "companies": [], |
| 14150 | + "giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/2866.beautiful-towers-ii.md", |
| 14151 | + "solution": "https://github.com/azl397985856/leetcode/blob/master/problems/2866.beautiful-towers-ii.md", |
| 14152 | + "code": [ |
| 14153 | + { |
| 14154 | + "language": "py", |
| 14155 | + "text": "\nclass Solution:\n def maximumSumOfHeights(self, maxHeight: List[int]) -> int:\n # 枚举 i 作为顶峰,其取值贪心的取 maxHeight[i]\n # 其左侧第一个小于它的位置 l,[l + 1, i] 都可以且最多取到 maxHeight[i]\n n = len(maxHeight)\n f = [-1] * n # f[i] 表示 i 为峰顶,左侧高度和最大值\n g = [-1] * n # g[i] 表示 i 为峰顶,右侧高度和最大值\n def cal(f):\n st = []\n for i in range(len(maxHeight)):\n while st and maxHeight[i] < maxHeight[st[-1]]:\n st.pop()\n # 其左侧第一个小于它的位置 l,[l + 1, i] 都可以且最多取到 maxHeight[i]\n if st:\n f[i] = (i - st[-1]) * maxHeight[i] + f[st[-1]]\n else:\n f[i] = maxHeight[i] * (i + 1)\n st.append(i)\n cal(f)\n maxHeight = maxHeight[::-1]\n cal(g)\n maxHeight = maxHeight[::-1]\n ans = 0\n for i in range(len(maxHeight)):\n ans = max(ans, f[i] + g[n - 1 - i] - maxHeight[i])\n return ans\n" |
| 14156 | + } |
| 14157 | + ] |
| 14158 | +}, |
14182 | 14159 | "selling-pieces-of-wood":{
|
14183 | 14160 | "id": "5254",
|
14184 | 14161 | "name": "selling-pieces-of-wood",
|
|
0 commit comments