討論串[閒聊] 每日leetcode
共 1554 篇文章
內容預覽:
1352. Product of the Last K Numbers. ## 思路. Prefix Product. 用size_紀錄目前Product的個數. 如果add 0 就reset Prefix跟size_. getProduct: prefix[-1] / prefix[size_-k
(還有683個字)
內容預覽:
2342. Max Sum of a Pair With Equal Sum of Digits. ## 思路. 用hash table紀錄digitSum的最大值. table有相同的digitSum就計算兩數和. ## Code. ```cpp. class Solution {. public
(還有551個字)
內容預覽:
昨天的. 題目:. 有一個array叫nums裡面有很多數字. 我們要找裡面有幾對符合i<j且nums[j]-nums[i]!=j-i. 思路:. 先去算有幾對符合nums[j]-nums[i]!=j-i. 再用全部去扣. nums[j]-nums[i]=j-i移項可以變成nums[j]-j=num
(還有455個字)
內容預覽:
改算good_pair數目. 再用減的. 一二三四五. def countBadPairs(self, nums):. """. :type nums: List[int]. :rtype: int. """. good_pair_cnt = 0. cnt = defaultdict(int). c
(還有139個字)
內容預覽:
2364. Count Number of Bad Pairs. ## 思路. Bad pair: i < j and j - i != nums[j] - nums[i]. 移項後, nums[j] - j != nums[i] - i. 所以建個counter, 紀錄(nums[i]-i) 的個
(還有340個字)