Skip to content

Commit 1549cc5

Browse files
author
robot
committed
fix: 修复力扣改版后无法使用的问题
1 parent 5ddd4f6 commit 1549cc5

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "leetcode cheatsheet",
44
"description": "刷题小助手,made by 力扣加加",
5-
"version": "0.10.6",
5+
"version": "0.11.0",
66
"browser_action": {
77
"default_popup": "index.html",
88
"default_title": "力扣加加"

src/db/root.db.js

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,12 +2565,60 @@
25652565
"sort-colors":{
25662566
"id": "75",
25672567
"name": "sort-colors",
2568-
"pre": [],
2569-
"keyPoints": [],
2570-
"companies": [],
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+
],
25712606
"giteeSolution": "https://gitee.com/golong/leetcode/blob/master/problems/75.sort-colors.md",
25722607
"solution": "https://github.com/azl397985856/leetcode/blob/master/problems/75.sort-colors.md",
2573-
"code": []
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+
]
25742622
},
25752623
"subsets":{
25762624
"id": "78",
@@ -13782,6 +13830,26 @@
1378213830
"text": "反向思考,题目要找最少操作数,其实就是找最多保留多少个数",
1378313831
"link": null,
1378413832
"color": "blue"
13833+
},
13834+
{
13835+
"text": "对于每一个num我们需要找到其作为左端点时,那么右端点就是v+on",
13836+
"link": null,
13837+
"color": "blue"
13838+
},
13839+
{
13840+
"text": "1,于是我们在这个数组中找值在num和v+on",
13841+
"link": null,
13842+
"color": "blue"
13843+
},
13844+
{
13845+
"text": "1的有多少个,这些都是可以保留的",
13846+
"link": null,
13847+
"color": "blue"
13848+
},
13849+
{
13850+
"text": "排序+二分减少时间复杂度",
13851+
"link": null,
13852+
"color": "blue"
1378513853
}
1378613854
],
1378713855
"companies": [],
@@ -13790,7 +13858,7 @@
1379013858
"code": [
1379113859
{
1379213860
"language": "py",
13793-
"text": "\n\nimport bisect\n\n\nclass Solution:\n def minOperations(self, nums: List[int]) -> int:\n ans = on = len(nums)\n nums = list(set(nums))\n nums.sort()\n n = len(nums)\n for i, v in enumerate(nums):\n r = bisect.bisect_right(nums, v + on - 1)\n l = bisect.bisect_left(nums, v - on + 1)\n ans = min(ans, n - (r - i), n - (i - l + 1))\n return ans + (on - n)\n\n"
13861+
"text": "\n\nimport bisect\n\n\nclass Solution:\n def minOperations(self, nums: List[int]) -> int:\n ans = on = len(nums)\n nums = list(set(nums))\n nums.sort()\n n = len(nums)\n for i, v in enumerate(nums):\n # nums[i] 一定有一个是在端点的,如果都不在端点,变成在端点不会使得答案更差\n r = bisect.bisect_right(nums, v + on - 1) # 枚举 i 作为左端点\n l = bisect.bisect_left(nums, v - on + 1) # 枚举 i 作为右端点\n ans = min(ans, n - (r - i), n - (i - l + 1))\n return ans + (on - n)\n\n"
1379413862
}
1379513863
]
1379613864
},

0 commit comments

Comments
 (0)