We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 701e5c7 commit 620363bCopy full SHA for 620363b
5.leetcode/src/com/fanxb/interview/Q46.java
@@ -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