add
This commit is contained in:
parent
701e5c7b95
commit
620363be94
27
5.leetcode/src/com/fanxb/interview/Q46.java
Normal file
27
5.leetcode/src/com/fanxb/interview/Q46.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package com.fanxb.interview;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA
|
||||||
|
*
|
||||||
|
* @author fanxb
|
||||||
|
* Date: 2020/6/9 15:10
|
||||||
|
*/
|
||||||
|
public class Q46 {
|
||||||
|
|
||||||
|
public int translateNum(int num) {
|
||||||
|
String str = String.valueOf(num);
|
||||||
|
//a=f(0),b=f(1)
|
||||||
|
int a = 1, b = 1, sum = 1;
|
||||||
|
for (int i = 1, length = str.length(); i < length; i++) {
|
||||||
|
String temp = str.substring(i - 1, i + 1);
|
||||||
|
sum = temp.compareTo("10") >= 0 && temp.compareTo("25") <= 0 ? a + b : b;
|
||||||
|
a = b;
|
||||||
|
b = sum;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(new Q46().translateNum(12258));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user