Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9a1d9e

Browse files
committed
[20220822] day1 prefix sum 문제 풀이
1 parent 9269d32 commit d9a1d9e

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

‎study-plan/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://leetcode.com/study-plan/

‎study-plan/leetcode-75/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://leetcode.com/study-plan/leetcode-75/?progress=xxpdgksv
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# https://leetcode.com/problems/find-pivot-index/
2+
# 724. Find Pivot Index
3+
from typing import List
4+
5+
6+
class Solution:
7+
def pivotIndex(self, nums: List[int]) -> int:
8+
total = sum(nums)
9+
left_sum = 0
10+
11+
for i in range(len(nums)):
12+
if left_sum == (total - nums[i] - left_sum):
13+
return i
14+
left_sum += nums[i]
15+
return -1
16+
17+
18+
if __name__ == '__main__':
19+
sol = Solution()
20+
print(sol.pivotIndex([1, 7, 3, 6, 5, 6]))
21+
print(sol.pivotIndex([1, 2, 3]))
22+
print(sol.pivotIndex([2, 1, -1]))
23+
# 사실 아래 케이스에서는 안돌아가는데 코드는 통과가 됨...
24+
# https://leetcode.com/problems/find-pivot-index/discuss/136167/This-is-a-very-poorly-described-problem
25+
print(sol.pivotIndex([-1, -1, -1, 0, 1, 1]))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://leetcode.com/problems/running-sum-of-1d-array/
2+
# 1480. Running Sum of 1d Array
3+
from typing import List
4+
5+
6+
class Solution:
7+
def runningSum(self, nums: List[int]) -> List[int]:
8+
9+
for i in range(1, len(nums)):
10+
nums[i] += nums[i-1]
11+
return nums

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /