Find All Numbers Disappeared in an Array
https://www.lintcode.com/problem/find-all-numbers-disappeared-in-an-array/description
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Solution {
/**
* @param nums: a list of integers
* @return: return a list of integers
*/
public List<Integer> findDisappearedNumbers(int[] nums) {
// write your code here
Arrays.sort(nums);
List<Integer> list = new ArrayList<>();
if (nums[0] > 1) {
list.add(1);
}
int max = nums.length;
while (nums[nums.length - 1] < max) {
list.add(max);
max--;
}
for (int i = 1; i < nums.length; i++) {
int num = nums[i];
while (num - nums[i - 1] > 1) {
list.add(num - 1);
num--;
}
}
return list;
}
}
相關文章
- 448. Find All Numbers Disappeared in an ArrayAPP
- LeetCode 448. Find All Numbers Disappeared in an ArrayLeetCodeAPP
- Leetcode 442. Find All Duplicates in an ArrayLeetCode
- #442-Find All Duplicates in an Array-陣列中重複的數字陣列
- B. Find The Array
- Leetcode[421] Maximum XOR of Two Numbers in an ArrayLeetCode
- LeetCode Patching Array All In OneLeetCode
- JavaScript object array sort by string bug All In OneJavaScriptObject
- Disappeared薦APP
- [leetcode] 1394. Find Lucky Integer in an ArrayLeetCode
- LeetCode 438. Find All Anagrams in a StringLeetCode
- Find Minimum in Rotated Sorted Array leetcode javaLeetCodeJava
- Leetcode-Find Minimum in Rotated Sorted ArrayLeetCode
- Leetcode 34 Find First and Last Position of Element in Sorted ArrayLeetCodeAST
- Leetcode-Find Minimum in Rotated Sorted Array IILeetCode
- [Javascript] Find Items from the end of the JavaScript Array using at, findLast and findLastIndexJavaScriptASTIndex
- LeetCode | 153. Find Minimum in Rotated Sorted ArrayLeetCode
- Leetcode 153. Find Minimum in Rotated Sorted ArrayLeetCode
- [LeetCode] 3011. Find if Array Can Be SortedLeetCode
- (轉)leetcode:Find All Anagrams in a String 滑動視窗方法總結LeetCode
- 400多種Numbers模板 DesiGN for Numbers Templates for macMac
- Acdream 1205 Disappeared Block(模擬)APPBloC
- All mirror URLs are not using ftp, http[s] or file. Cannot find a valid baseurl for repo: baseFTPHTTP
- [LeetCode] Find Minimum in Rotated Sorted Array (包含遞增和遞減旋轉)LeetCode
- 轉摘plsql高階程式設計_table_array_for all_bulk collect into_fetchSQL程式設計
- Codeforces - Jzzhu and Numbers
- different random numbers generatorrandom
- Collecting Numbers II
- array new 與 array deletedelete
- PHP array_flip() array_merge() array+array的使用總結PHP
- array
- Leetcode - Bitwise AND of Numbers RangeLeetCode
- LeetCode-Lexicographical NumbersLeetCode
- Array()與Array.of()方法區別
- JS Array.reduce 實現 Array.map 和 Array.filterJSFilter
- PHP用foreach來表達array_walk/array_filter/array_map/array_reducePHPFilter
- array_filter ()、array_map ()、array_walk () 區別?容易記混淆!!!Filter
- docker in allDocker