Skip to content

Commit b079d3a

Browse files
authored
Create digital_problem.py
1 parent c9e1085 commit b079d3a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

digital_problem.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
"""
3+
@param n: the number n
4+
@return: the times n convert to 1
5+
"""
6+
def digitConvert(self, n):
7+
# Write your code here
8+
i = 0
9+
while n != 1:
10+
if (n % 2) == 0:
11+
n = n / 2
12+
else:
13+
n = n * 3 + 1
14+
i += 1
15+
return i
16+
17+
# easy: http://lintcode.com/zh-cn/problem/digital-problem/

0 commit comments

Comments
 (0)