Re: [閒聊] 每日leetcode已回收
看板Marginalman作者DJYOSHITAKA (franchouchouISBEST)時間1年前 (2024/06/12 22:58)推噓2(2推 0噓 3→)留言5則, 4人參與討論串350/1548 (看更多)
一開始想說就cnt 但感覺應該有一些其他方法
肥肥只想到類似快排的方法
三指標什麼軌 你們怎麼想到的
醫生就這樣了
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
pivot = 1
n = len(nums)
i = 0
for j in range(0,n):
if nums[j]<pivot:
nums[j], nums[i] = nums[i], nums[j]
i += 1
if i<n and nums[i]<pivot:
i += 1
pivot = 2
for j in range(i,n):
if nums[j]<pivot:
nums[j], nums[i] = nums[i], nums[j]
i += 1
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.137.251.107 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1718204293.A.D4C.html
推
06/12 23:00,
1年前
, 1F
06/12 23:00, 1F
推
06/12 23:01,
1年前
, 2F
06/12 23:01, 2F
→
06/12 23:01,
1年前
, 3F
06/12 23:01, 3F
→
06/12 23:02,
1年前
, 4F
06/12 23:02, 4F
→
06/12 23:03,
1年前
, 5F
06/12 23:03, 5F
討論串 (同標題文章)
完整討論串 (本文為第 350 之 1548 篇):