~/leetcode$cat3498. Reverse Degree of a String
This problem is pretty straight-forward, the description basically explains what to do. I guess one nice thing that you can do is to use ord() (if using python) to calculate the reverse alphabet index easily.
Beautiful, sub 1 minute solution :D
class Solution:
def reverseDegree(self, s: str) -> int:
res = 0
for i, c in enumerate(s):
reverse_index = 26 - (ord(c) - ord('a'))
res += (reverse_index * (i + 1))
return res
Time Complexity:
O(n)Space Complexity:
O(1)Time Taken:
59s
Runtime:
7 msMemory:
19.1 MBTests Passed:
933/933