Skip to content

Commit 620363b

Browse files
committed
add
1 parent 701e5c7 commit 620363b

File tree

1 file changed

+27
-0
lines changed
  • 5.leetcode/src/com/fanxb/interview

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fanxb.interview;
2+
3+
/**
4+
* Created with IntelliJ IDEA
5+
*
6+
* @author fanxb
7+
* Date: 2020/6/9 15:10
8+
*/
9+
public class Q46 {
10+
11+
public int translateNum(int num) {
12+
String str = String.valueOf(num);
13+
//a=f(0),b=f(1)
14+
int a = 1, b = 1, sum = 1;
15+
for (int i = 1, length = str.length(); i < length; i++) {
16+
String temp = str.substring(i - 1, i + 1);
17+
sum = temp.compareTo("10") >= 0 && temp.compareTo("25") <= 0 ? a + b : b;
18+
a = b;
19+
b = sum;
20+
}
21+
return sum;
22+
}
23+
24+
public static void main(String[] args) {
25+
System.out.println(new Q46().translateNum(12258));
26+
}
27+
}

0 commit comments

Comments
 (0)