This commit is contained in:
fanxb 2021-03-27 15:54:27 +08:00
parent 90dd4ad4ea
commit d0f10cc8f1
3 changed files with 87 additions and 0 deletions

View File

@ -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<Integer> 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})));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}