diff --git a/5.leetcode/src/com/fanxb/common/Q739.java b/5.leetcode/src/com/fanxb/common/Q739.java new file mode 100644 index 0000000..621efbb --- /dev/null +++ b/5.leetcode/src/com/fanxb/common/Q739.java @@ -0,0 +1,34 @@ +package com.fanxb.common; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedList; + +/** + * Created with IntelliJ IDEA + * + * @author fanxb + * Date: 2020/6/11 10:58 + */ +public class Q739 { + public int[] dailyTemperatures(int[] T) { + if (T.length == 0) { + return new int[0]; + } + LinkedList linkedList = new LinkedList<>(); + int[] res = new int[T.length]; + for (int i = 0; i < T.length; i++) { + int j = 0; + while (linkedList.size() > j && T[linkedList.get(j)] > T[i]) { + j++; + } + linkedList.add(j, i); + res[linkedList.get(j)] = i - linkedList.get(j); + } + return res; + } + + public static void main(String[] args) { + System.out.println(Arrays.toString(new Q739().dailyTemperatures(new int[]{1, 2, 3}))); + } +} diff --git a/5.leetcode/src/com/fanxb/common/Q9.java b/5.leetcode/src/com/fanxb/common/Q9.java new file mode 100644 index 0000000..f0f654f --- /dev/null +++ b/5.leetcode/src/com/fanxb/common/Q9.java @@ -0,0 +1,35 @@ +package com.fanxb.common; + +/** + * Created with IntelliJ IDEA + * + * @author fanxb + * Date: 2020/6/10 10:49 + */ +public class Q9 { + + public boolean isPalindrome(int x) { + //小于0的数或者末尾为0的正数肯定不是回文数 + if (x < 0 || (x > 0 && x % 10 == 0)) { + return false; + } + long temp = 1; + while (x / (temp * 10) > 0) { + temp = temp * 10; + } + for (int i = 1; i < temp; temp = temp / 10, i *= 10) { + System.out.println(x / i % 10 + ":" + x / temp % 10); + if (x / i % 10 != x / temp % 10) { + return false; + } + } + return true; + } + + public static void main(String[] args) { + Q9 instance = new Q9(); + System.out.println(instance.isPalindrome(1212312)); + System.out.println(instance.isPalindrome(1410110141)); + System.out.println(instance.isPalindrome(-121)); + } +} diff --git a/5.leetcode/src/com/fanxb/interview/Q64.java b/5.leetcode/src/com/fanxb/interview/Q64.java new file mode 100644 index 0000000..57c4f15 --- /dev/null +++ b/5.leetcode/src/com/fanxb/interview/Q64.java @@ -0,0 +1,18 @@ +package com.fanxb.interview; + +/** + * Created with IntelliJ IDEA + * + * @author fanxb + * Date: 2020/6/11 9:56 + */ +public class Q64 { + public int sumNums(int n) { + boolean temp = n - 1 > 0 && (n += sumNums(n - 1)) > 0; + return n; + } + + public static void main(String[] args) { + System.out.println(new Q64().sumNums(10)); + } +}