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 3d14ae4 commit 8fc1dd4Copy full SHA for 8fc1dd4
1 file changed
missing-number/gyeo-ri.py
@@ -1,18 +1,16 @@
1
"""
2
[결과 요약]
3
-# 재시도횟수: 1회
+# 재시도횟수: 2회
4
1. 반복문으로 구하기: 로직은 쉬우나 n이 최대 10^4이므로 input 길이에 따라 속도가 느려질 수 있음
5
+ 2. 등차수열의 원리를 활용하여 n!을 구한 다음 nums의 합을 빼주기
6
7
8
9
class Solution:
10
def missingNumber(self, nums: list[int]) -> int:
11
len_nums = len(nums)
- for i in range(len_nums + 1):
12
- if i not in nums:
13
- return i
14
-
15
- raise Exception("No Answer")
+ total_sum = int(len_nums * (len_nums + 1) / 2)
+ return total_sum - sum(nums)
16
17
18
if __name__ == "__main__":
0 commit comments