討論串[閒聊] 每日LeetCode
共 719 篇文章

推噓4(4推 0噓 1→)留言5則,0人參與, 1年前最新作者wu10200512 (廷廷)時間1年前 (2024/02/20 15:02), 編輯資訊
0
0
0
內容預覽:
XOR原本聽你們講想用用看. 但沒用過寫不出來. 然後就開vector計數再找. O(2n)還以為很爛. 結果beat99. 0.0. 268. Missing Number. class Solution {. public:. int missingNumber(vector<int>& num
(還有131個字)

推噓3(3推 0噓 0→)留言3則,0人參與, 1年前最新作者pandix (麵包屌)時間1年前 (2024/02/20 10:42), 編輯資訊
0
0
1
內容預覽:
想到之前看過的一招 就是把每個數字換到他對應的 index. index 是 range(n). nums 是 range(n+1) 少掉某個數字. 所以 nums 裡會多一個數字 n 放在少掉的那個 index. ex: n=8 少掉 3 這個數字. index 0 1 2 3 4 5 6 7.
(還有666個字)

推噓1(1推 0噓 1→)留言2則,0人參與, 1年前最新作者JIWP (神楽めあ的錢包)時間1年前 (2024/02/20 10:07), 編輯資訊
0
0
1
內容預覽:
今天又是easy,好爽哦. 這題就一直xor答案就出來了. C code:. int missingNumber(int* nums, int numsSize) {. int ans=numsSize;. for (int i=0;i<numsSize;i++){. ans^=i;. ans^=n
(還有32個字)

推噓1(1推 0噓 1→)留言2則,0人參與, 1年前最新作者JerryChungYC (JerryChung)時間1年前 (2024/02/20 08:30), 編輯資訊
0
0
1
內容預覽:
https://leetcode.com/problems/missing-number/. 268. Missing Number. 給一個包含[0, n]範圍內不同數字的陣列nums,傳回範圍內唯一缺少的數字. Example 1:. Input: nums = [3,0,1]. Output:
(還有362個字)

推噓1(1推 0噓 1→)留言2則,0人參與, 1年前最新作者wu10200512 (廷廷)時間1年前 (2024/02/19 11:01), 編輯資訊
0
0
0
內容預覽:
前幾天看C考題看到一模一樣的. 一行解決. 非常好布林. 231. Power of Two. class Solution {. public:. bool isPowerOfTwo(int n) {. return n>0 && (n & n-1)==0;. }. };. --. 發信站: