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
‹
›
Home
View web version
No comments:
Post a Comment