From 620363be94f1e03bbe3248959492f470ede4ac97 Mon Sep 17 00:00:00 2001 From: fanxb Date: Tue, 9 Jun 2020 17:45:11 +0800 Subject: [PATCH] add --- 5.leetcode/src/com/fanxb/interview/Q46.java | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 5.leetcode/src/com/fanxb/interview/Q46.java diff --git a/5.leetcode/src/com/fanxb/interview/Q46.java b/5.leetcode/src/com/fanxb/interview/Q46.java new file mode 100644 index 0000000..dec5dfb --- /dev/null +++ b/5.leetcode/src/com/fanxb/interview/Q46.java @@ -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)); + } +}