IrisJavaDiary
Monday, October 8, 2018
268. Missing Number
class Solution {
public int missingNumber(int[] nums) {
long expected = nums.length * (nums.length + 1) / 2;
for (int n : nums) {
expected -= n;
}
return (int) expected;
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment