We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 945c067 commit 106fa12Copy full SHA for 106fa12
src/main/java/com/fishercoder/solutions/_268.java
@@ -17,4 +17,15 @@ public int missingNumber(int[] nums) {
17
}
18
19
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
+
31
0 commit comments