leetcode刷题22天
171. Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
Example 1:
Input: “A”
Output: 1
Example 2:
Input: “AB”
Output: 28
Example 3:
Input: “ZY”
Output: 701
代码:
class Solution {
public int titleToNumber(String s) {
if(s.length()<=0)
return 0;
int count = 1,res = 0;
for(int i = s.length()-1;i>=0;i--) {
res = res + ((int)s.charAt(i)-64)*count;
count = count * 26;
}
return res;
}
}
- Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.
Example 1:
Input: 3
Output: 0
Explanation: 3! = 6, no trailing zero.
Example 2:
Input: 5
Output: 1
Explanation: 5! = 120, one trailing zero.
代码:
class Solution {
public static int trailingZeroes(int n) {
if(n==0)
return 0;
int res = 0;
while(n>0) {
res = res + n/5;
n = n/5;
}
return res;
}
}