Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 데이콘
- Kaggle
- ChatGPT
- 프로그래머스
- leetcode
- 프로그래머스 파이썬
- hackerrank
- 맥북
- AI 경진대회
- PYTHON
- 코로나19
- dacon
- Real or Not? NLP with Disaster Tweets
- Git
- Docker
- ubuntu
- 파이썬
- 자연어처리
- 우분투
- 편스토랑
- programmers
- 편스토랑 우승상품
- gs25
- github
- 백준
- 더현대서울 맛집
- 금융문자분석경진대회
- Baekjoon
- 캐치카페
- SW Expert Academy
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1299. Replace Elements with Greatest Element on Right Side (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 1299. Replace Elements with Greatest Element on Right Side (Python)
솜씨좋은장씨 2020. 11. 7. 00:19728x90
반응형
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.
After doing so, return the array.
Example 1:
Input: arr = [17,18,5,4,6,1]
Output: [18,6,6,6,1,-1]
Constraints:
- 1 <= arr.length <= 10^4
- 1 <= arr[i] <= 10^5
Solution
class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
answer = [0] * len(arr)
answer[-1] = -1
for i in range(len(arr)-2, -1, -1):
answer[i] = max([answer[i+1], arr[i+1]])
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 867. Transpose Matrix (Python) (0) | 2020.11.09 |
---|---|
[leetCode] 43. Multiply Strings (Python) (0) | 2020.11.08 |
[leetCode] 1122. Relative Sort Array (Python) (0) | 2020.11.06 |
[leetCode] 1287. Element Appearing More Than 25% In Sorted Array (Python) (0) | 2020.11.05 |
[leetCode] 1380. Lucky Numbers in a Matrix (Python) (0) | 2020.11.04 |
Comments