728x90
문제 : https://leetcode.com/problems/rank-transform-of-an-array/description/
Rank Transform of an Array - LeetCode
Can you solve this real interview question? Rank Transform of an Array - Given an array of integers arr, replace each element with its rank. The rank represents how large the element is. The rank has the following rules: * Rank is an integer starting from
leetcode.com
난이도 : Easy
풀이
class Solution:
def arrayRankTransform(self, arr: List[int]) -> List[int]:
ans = []
sortedArr = sorted(arr)
d = {}
rank = 1
for i in sortedArr:
if i not in d:
d[i] = rank
rank += 1
for i in arr:
ans.append(d[i])
return ans
728x90