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
- 데이콘
- PYTHON
- 편스토랑 우승상품
- hackerrank
- programmers
- ubuntu
- 백준
- 프로그래머스
- 더현대서울 맛집
- 우분투
- 맥북
- 프로그래머스 파이썬
- Docker
- 캐치카페
- SW Expert Academy
- Baekjoon
- Real or Not? NLP with Disaster Tweets
- 코로나19
- gs25
- ChatGPT
- 자연어처리
- 편스토랑
- AI 경진대회
- leetcode
- 금융문자분석경진대회
- github
- dacon
- 파이썬
- Git
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