Skip to content

Commit f541aa1

Browse files
committed
feat: 가독성/메모리 사용량은 떨어지지만 속도가 빠른 옵션 추가
1 parent 8fc1dd4 commit f541aa1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

missing-number/gyeo-ri.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88

99
class Solution:
1010
def missingNumber(self, nums: list[int]) -> int:
11+
# (Runtime: 3ms / Beats 61.16%, Memory 20.23MB / Beats: 98.53% )
1112
len_nums = len(nums)
1213
total_sum = int(len_nums * (len_nums + 1) / 2)
1314
return total_sum - sum(nums)
1415

16+
"""
17+
이때, 아래와 같이 변수 선언 없이 계산하면(In Memory) 메모리는 조금 더 쓰지만 속도는 빨라진다.
18+
(Runtime: 0ms / Beats 100.00%, Memory 20.34MB / Beats: 90.41% )
19+
return int(len(nums) * (len(nums) + 1) / 2) - sum(nums)
20+
"""
21+
1522

1623
if __name__ == "__main__":
1724
test_cases = [

0 commit comments

Comments
 (0)