Skip to content

Commit 309a3bd

Browse files
committed
Excel Sheet Column Title/ Factorial Trailing Zeroes
1 parent bd723a5 commit 309a3bd

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

168 Excel Sheet Column Title.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''
2+
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
3+
4+
For example:
5+
6+
1 -> A
7+
2 -> B
8+
3 -> C
9+
...
10+
26 -> Z
11+
27 -> AA
12+
28 -> AB
13+
'''
14+
15+
class Solution(object):
16+
def convertToTitle(self, n):
17+
"""
18+
:type n: int
19+
:rtype: str
20+
"""
21+
result = []
22+
base = ord('A')
23+
while n:
24+
n, r = divmod(n - 1, 26)
25+
result.append(chr(base + r))
26+
return ''.join(result[::-1])
27+
28+
29+
if __name__ == "__main__":
30+
assert Solution().convertToTitle(1) == 'A'
31+
assert Solution().convertToTitle(28) == 'AB'

172 Factorial Trailing Zeroes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
Given an integer n, return the number of trailing zeroes in n!.
3+
4+
Note: Your solution should be in logarithmic time complexity.
5+
'''
6+
7+
class Solution(object):
8+
def trailingZeroes(self, n):
9+
"""
10+
:type n: int
11+
:rtype: int
12+
"""
13+
count = 0
14+
while n:
15+
n //= 5
16+
count += n
17+
return count
18+
19+
20+
if __name__ == "__main__":
21+
assert Solution().trailingZeroes(25) == 6

0 commit comments

Comments
 (0)