Skip to content

Commit 619227e

Browse files
committed
#235 solution
1 parent 925e4b5 commit 619227e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
ํ’€์ด :
3+
์ˆ˜์‹์„ ์ด์šฉํ•ด ์ˆซ์ž๊ฐ€ ๋น ์ง€์ง€ ์•Š์•˜์„๊ฒฝ์šฐ ์ดํ•ฉ์„ ๊ตฌํ•˜๊ณ  nums๋ฅผ ์ˆœํšŒํ•˜๋ฉด์„œ ์ˆซ์ž๋“ค์„ ๋นผ๋ฉด ๋‚จ์€ ์ˆซ์ž๊ฐ€ missing No.
4+
5+
nums์˜ ๊ธธ์ด : N
6+
7+
TC : O(N)
8+
9+
SC : O(1)
10+
*/
11+
12+
#include <vector>
13+
using namespace std;
14+
15+
class Solution {
16+
public:
17+
int missingNumber(vector<int>& nums) {
18+
int n = nums.size();
19+
int sum = n * (n + 1) / 2;
20+
21+
for (auto& num : nums)
22+
sum -= num;
23+
return sum;
24+
}
25+
};

0 commit comments

Comments
ย (0)