https://leetcode.com/problems/ant-on-the-boundary/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1
2
3
4
5
6
7
8
|
class Solution:
def returnToBoundaryCount(self, nums: List[int]) -> int:
location = answer = 0
for num in nums:
location += num
if location == 0:
answer += 1
return answer
|
cs |
처음에는 원점(원문에는 boundary 라고 표현합니다)으로 돌아올수 있는지 아닌지 를
묻는 문제인줄알고 누적합을 사용했는데
그게 아니라 돌아올수있을때마다 answer 에다가 더하기 1을 해줘야되네요
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2937. Make Three Strings Equal (0) | 2024.02.08 |
---|---|
백준 25206 너의 평점은 (0) | 2024.02.06 |
leetcode 3019. Number of Changing Keys (0) | 2024.02.05 |
백준 9063 대지 (0) | 2024.01.24 |
leetcode 3014. Minimum Number of Pushes to Type Word I (1) | 2024.01.23 |
댓글