Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 106fa12

Browse files
add 268
1 parent 945c067 commit 106fa12

File tree

1 file changed

+11
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+11
-0
lines changed

src/main/java/com/fishercoder/solutions/_268.java

+11
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,15 @@ public int missingNumber(int[] nums) {
1717
}
1818
}
1919

20+
public static class Solution2 {
21+
public int missingNumber(int[] nums) {
22+
int n = nums.length;
23+
long sum = n + (n * n - n) / 2;//this is the formula to compute the sum for arithmetic sequence
24+
for (int i = 0; i < nums.length; i++) {
25+
sum -= nums[i];
26+
}
27+
return (int) sum;
28+
}
29+
}
30+
2031
}

0 commit comments

Comments
 (0)