【easy】268. Missing Number
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n
, find the one that is missing from the array.
Example 1
Input: [3,0,1] Output: 2
Example 2
Input: [9,6,4,2,3,5,7,0,1] Output: 8
用異或的辦法:
class Solution { public: int missingNumber(vector<int>& nums) { int len = nums.size();if(len == 0) return 0; int x = 0; for (int i=1;i<=len;i++) x ^= i; for (int i=0;i<len;i++) x ^= nums[i]; return x; } };
【easy】268. Missing Number
相關推薦
【easy】268. Missing Number
color urn nbsp gpo size input tin i++ array Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is
【python3】leetcode 268. Missing Number (easy)
268. Missing Number (easy) Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is
【easy】Number of Segments in a String 字符串中的分段數量
turn size 遍歷 字符串 分隔 pre number nts color 以空格為分隔符,判斷一個string可以被分成幾部分。 註意幾種情況:(1)全都是空格 (2)空字符串(3)結尾有空格 思路: 只要統計出單詞的數量即可。那麽我們的做法是遍歷字符串,遇到空格直
268. Missing Number - Easy
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1:
Leetcode_Array -- 268. Missing Number [easy]
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. 給定一個包含n個不同的數字的陣列,找到
mysql錯誤【一】[ERROR] Missing system table mysql.proxies_priv
mysql錯誤 環境:mysql一主一從架構,主庫是mysql5.1,從庫是mysql5.6;系統均為CentOS6.2 問題: 在主庫上面執行的SQL語句 1.創建表 CREATE TABLE `app_versions` ( `date` date NO
【Lintcode】046.Majority Number
his oot log light ntc else white hit lte 題目: Given an array of integers, the majority number is the number that occurs more than half o
【Leetcode】137. Single Number II
val tar urn arr ber and mos calc cal 題目: Given an array of integers, every element appears three times except for one. Find that single o
189. Rotate Array【easy】
you could turn and start num tco extra tor 189. Rotate Array【easy】 Rotate an array of n elements to the right by k steps. For example, w
26. Remove Duplicates from Sorted Array【easy】
() 邊界條件 return arr ray constant eas 註意 rom 26. Remove Duplicates from Sorted Array【easy】 Given a sorted array, remove the duplicates in p
27. Remove Element【easy】
problem rip order bottom att else ont scrip sar 27. Remove Element【easy】 Given an array and a value, remove all instances of that value i
680. Valid Palindrome II【easy】
遞歸 bsp user sta temp code pla lean 我們 680. Valid Palindrome II【easy】 Given a non-empty string s, you may delete at most one character. J
521. Longest Uncommon Subsequence I【easy】
str efi cau () appear som delet pear empty 521. Longest Uncommon Subsequence I【easy】 Given a group of two strings, you need to find the
557. Reverse Words in a String III【easy】
ext nco 下標 返回值 pan leetcode oct rac ann 557. Reverse Words in a String III【easy】 Given a string, you need to reverse the order of charac
28. Implement strStr()【easy】
imp strstr tro nbsp col pre code ring tac 28. Implement strStr()【easy】 Implement strStr(). Returns the index of the first occurrence of
383. Ransom Note【easy】
begin logs char rar assume ron return code color 383. Ransom Note【easy】 Given an arbitrary ransom note string and another string contain
606. Construct String from Binary Tree 【easy】
new mos pen you image color emp same exce 606. Construct String from Binary Tree 【easy】 You need to construct a string consists of paren
345. Reverse Vowels of a String【easy】
not blog ive 參考 char wap ast otc emp 345. Reverse Vowels of a String【easy】 Write a function that takes a string as input and reverse o
217. Contains Duplicate【easy】
cti color ont dup empty algorithm appears lean sed 217. Contains Duplicate【easy】 Given an array of integers, find if the array contains
561. Array Partition I【easy】
cas positive output not big ren emp let malle 561. Array Partition I【easy】 Given an array of 2n integers, your task is to group these in