Number
進制轉換
10進位 integer to string %10 /10
Given integer n
int[] digits
int len
while(len > 0){
digits[len--] = n%10;
n/=10;
}13. Roman to Integer
Given a roman numeral, convert it to an integer.
The answer is guaranteed to be within the range from 1 to 3999.
7 characters
Add number from left to right
Test if left char is smaller than cur char
def romanToInt(self, s: str) -> int:
dic = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
num = dic[s[0]]
for i in range(1, len(s)):
num += dic[s[i]]
if dic[s[i]] > dic[s[i-1]]:
num -= dic[s[i-1]]*2
return num12 Integer to Roman
Given an integer, convert it to a roman numeral.
The number is guaranteed to be within the range from 1 to 3999.
13 strings
倍數數字 = 該roman number 重複數
8. String to Integer(atoi)
Leetcode 8
Use long store
The number could be bigger than Long
50. Pow(x, n)
69. Sqrt
273 Integer to English Word
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1.
Last updated
Was this helpful?