728x90
https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/
class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
result = []
before = max(arr)
for i in range(len(arr) - 1):
if arr[i] == before:
before = max(arr[i+1:])
result.append(before)
result.append(-1)
return result
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2356. Number of Unique Subjects Taught by Each Teacher (0) | 2023.08.28 |
---|---|
[Leetcode] 941. Valid Mountain Array (0) | 2023.08.28 |
[Leetcode] 922. Sort Array By Parity II (0) | 2023.08.26 |
[Leetcode] 905. Sort Array By Parity (0) | 2023.08.26 |
[Leetcode] 620. Not Boring Movies (0) | 2023.08.25 |