Skip to content

Commit

Permalink
Create 503.py
Browse files Browse the repository at this point in the history
  • Loading branch information
zxzl committed Jan 19, 2021
1 parent 732c9f7 commit 5221a63
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions python/503.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
naive(ㅜㅜ): O(N^2)
"""

class Solution:
def nextGreaterElements(self, nums: List[int]) -> List[int]:
N = len(nums)
ans = []


for (i, num) in enumerate(nums):
curr = (i + 1) % N

found = False
while not found and curr != i:
if nums[curr] > num:
ans.append(nums[curr])
found=True
else:
curr = (curr+1)%N

if not found:
ans.append(-1)

return ans

0 comments on commit 5221a63

Please sign in to comment.