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;
}
}
相關文章
- 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
- 421-Maximum XOR of Two Numbers in an Array
- LeetCode Patching Array All In OneLeetCode
- LeetCode 438. Find All Anagrams in a StringLeetCode
- [leetcode] 1394. Find Lucky Integer in an ArrayLeetCode
- Find Minimum in Rotated Sorted Array I & II
- [LeetCode] 3011. Find if Array Can Be SortedLeetCode
- JavaScript object array sort by string bug All In OneJavaScriptObject
- LeetCode | 153. Find Minimum in Rotated Sorted ArrayLeetCode
- Leetcode 34 Find First and Last Position of Element in Sorted ArrayLeetCodeAST
- [Javascript] Find Items from the end of the JavaScript Array using at, findLast and findLastIndexJavaScriptASTIndex
- (轉)leetcode:Find All Anagrams in a String 滑動視窗方法總結LeetCode
- All mirror URLs are not using ftp, http[s] or file. Cannot find a valid baseurl for repo: baseFTPHTTP
- Reversed Numbers
- 400多種Numbers模板 DesiGN for Numbers Templates for macMac
- Collecting Numbers II
- Codeforces - Jzzhu and Numbers
- different random numbers generatorrandom
- LeetCode 2 Add Two NumbersLeetCode
- 165. Compare Version Numbers
- Leetcode 165 Compare Version NumbersLeetCode
- 201-Bitwise AND of Numbers Range
- 829. Consecutive Numbers Sum
- 【Lintcode】1267. Lexicographical Numbers
- Jenkins報錯'Gradle build daemon disappeared unexpectedly'的問題解決JenkinsGradleUIAPP
- BeautifulSoup4 find_all搜尋包含指定文字內容的標籤返回空list的問題
- Array.from和 Array.of
- array
- LeetCode-2 Add Two NumbersLeetCode
- Sum of Square Numbers 平方數之和
- Self Dividing Numbers 自除數
- LeetCode 2. Add Two NumbersLeetCode
- 129-Sum Root to Leaf Numbers
- Add_Two_Numbers python 求解Python
- B. Numbers Box(思維)