Skip to content

Commit

Permalink
publish
Browse files Browse the repository at this point in the history
  • Loading branch information
robot committed Oct 31, 2023
1 parent c2fd80e commit 37a8256
Show file tree
Hide file tree
Showing 3 changed files with 13,004 additions and 77 deletions.
Binary file modified leetcode-cheat.zip
Binary file not shown.
131 changes: 54 additions & 77 deletions src/db/root.db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2565,60 +2565,12 @@
"sort-colors":{
"id": "75",
"name": "sort-colors",
"pre": [
{
"text": "荷兰国旗问题",
"link": "https://en.wikipedia.org/wiki/Dutch_national_flag_problem",
"color": "purple"
},
{
"text": "排序",
"link": null,
"color": "purple"
}
],
"keyPoints": [
{
"text": "荷兰国旗问题",
"link": null,
"color": "blue"
},
{
"text": "countingsort",
"link": null,
"color": "blue"
}
],
"companies": [
{
"name": "阿里巴巴"
},
{
"name": "腾讯"
},
{
"name": "百度"
},
{
"name": "字节跳动"
}
],
"pre": [],
"keyPoints": [],
"companies": [],
"giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/75.sort-colors.md",
"solution": "https://github.com/azl397985856/leetcode/blob/master/problems/75.sort-colors.md",
"code": [
{
"language": "cpp",
"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"
},
{
"language": "py",
"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"
},
{
"language": "py",
"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"
}
]
"code": []
},
"subsets":{
"id": "78",
Expand Down Expand Up @@ -10730,34 +10682,12 @@
"snakes-and-ladders":{
"id": "909",
"name": "snakes-and-ladders",
"pre": [
{
"text": "广度优先遍历",
"link": null,
"color": "gold"
}
],
"keyPoints": [
{
"text": "根据矩阵编号如何算出其都在的行号和列号。这里其实用到了number=(row",
"link": null,
"color": "blue"
},
{
"text": "1)\\*n+col这样的一个公式,后面的所有公式都是基于它产生的。",
"link": null,
"color": "blue"
}
],
"pre": [],
"keyPoints": [],
"companies": [],
"giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/909.snakes-and-ladders.md",
"solution": "https://github.com/azl397985856/leetcode/blob/master/problems/909.snakes-and-ladders.md",
"code": [
{
"language": "py",
"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"
}
]
"code": []
},
"online-election":{
"id": "911",
Expand Down Expand Up @@ -14179,6 +14109,53 @@
}
]
},
"count-k-subsequences-of-a-string-with-maximum-beauty":{
"id": "2842",
"name": "count-k-subsequences-of-a-string-with-maximum-beauty",
"pre": [
{
"text": "排列组合",
"link": null,
"color": "green"
}
],
"keyPoints": [],
"companies": [],
"giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/2842.count-k-subsequences-of-a-string-with-maximum-beauty.md",
"solution": "https://github.com/azl397985856/leetcode/blob/master/problems/2842.count-k-subsequences-of-a-string-with-maximum-beauty.md",
"code": [
{
"language": "py",
"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"
}
]
},
"beautiful-towers-ii":{
"id": "2866",
"name": "beautiful-towers-ii",
"pre": [
{
"text": "动态规划",
"link": null,
"color": "red"
},
{
"text": "单调栈",
"link": null,
"color": "purple"
}
],
"keyPoints": [],
"companies": [],
"giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/2866.beautiful-towers-ii.md",
"solution": "https://github.com/azl397985856/leetcode/blob/master/problems/2866.beautiful-towers-ii.md",
"code": [
{
"language": "py",
"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"
}
]
},
"selling-pieces-of-wood":{
"id": "5254",
"name": "selling-pieces-of-wood",
Expand Down
Loading

0 comments on commit 37a8256

Please sign in to comment.