Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (廷廷)時間1年前 (2024/02/14 08:38), 編輯推噓4(400)
留言4則, 4人參與, 1年前最新討論串676/719 (看更多)
之前每日寫過了 今天再寫一次基本上長一模一樣 238. Product of Array Except Self class Solution { public: vector<int> productExceptSelf(vector<int>& nums) { vector<int> zeros; int n=nums.size(); int multi=1; for(int i=0; i<n; i++){ if(nums[i]==0){ zeros.push_back(i); } else{ multi*=nums[i]; } } vector<int> ans(n, 0); if(zeros.size()>1){ return ans; } else if(zeros.size()==1){ ans[zeros[0]]=multi; } else{ for(int i=0; i<n; i++){ ans[i]=multi/nums[i]; } } return ans; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.231.154.170 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1707899897.A.7B7.html

02/14 16:40, 1年前 , 1F
大師
02/14 16:40, 1F

02/14 16:40, 1年前 , 2F
大師
02/14 16:40, 2F

02/14 16:42, 1年前 , 3F
大師
02/14 16:42, 3F

02/14 17:11, 1年前 , 4F
你好帥
02/14 17:11, 4F
文章代碼(AID): #1bp7lvUt (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bp7lvUt (Marginalman)