Re: [閒聊] 每日leetcode

看板Marginalman作者 (franchouchouISBEST)時間1年前 (2024/03/29 22:31), 編輯推噓4(401)
留言5則, 5人參與, 1年前最新討論串78/1548 (看更多)
2962. Count Subarrays Where Max Element Appears at Least K Times 廢廢如我 只想到慢慢用map記index 都比那些sliding的慢 一生就這樣了 long long countSubarrays(vector<int>& nums, int k) { unordered_map<int,int> mp; int maxi = *max_element(nums.begin(), nums.end()); int cnt_now = 0; long long ans = 0; for(int i=0; i<nums.size(); i++) { if(nums[i] == maxi) { cnt_now += 1; mp[cnt_now] = i; } if(mp.find(cnt_now-k+1) != mp.end()) { ans += (mp[cnt_now-k+1]+1); } } return ans; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.228.146.144 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1711722695.A.450.html

03/29 22:33, 1年前 , 1F
大師,我連寫都不會寫
03/29 22:33, 1F

03/29 22:34, 1年前 , 2F
大師
03/29 22:34, 2F

03/29 22:38, 1年前 , 3F
大師 我連寫都不會寫
03/29 22:38, 3F

03/29 22:38, 1年前 , 4F
大師 我都不刷提了 小廢物是我
03/29 22:38, 4F

03/29 22:39, 1年前 , 5F
尼版剩我不會cpp了
03/29 22:39, 5F
文章代碼(AID): #1c1j37HG (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1c1j37HG (Marginalman)