Make a little change by checking if the stack is cleared in the 2nd round:

class Solution(object):
def nextGreaterElements(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
stack, r = [], [-1] * len(nums)
for i in range(len(nums)):
while stack and (nums[stack[-1]] < nums[i]):
r[stack.pop()] = nums[i]
stack.append(i)
for i in range(len(nums)):
while stack and (nums[stack[-1]] < nums[i]):
r[stack.pop()] = nums[i]
if stack == []:
break
return r

beats 98% of Python solutions...