编程题1 AC
import java.util.Arrays;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param digits int整型一维数组
* @return int整型
*/
public int maxDigit (int[] digits) {
// write code here
Arrays.sort(digits);
int ans = 0;
for (int i = digits.length - 1; i >= 0; i--) {
ans = ans * 10 + digits[i];
}
return ans;
}
}
编程题2AC
import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* public ListNode(int val) {
* this.val = val;
* }
* }
*/
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param node1 ListNode类
* @param node2 ListNode类
* @return ListNode类
*/
public ListNode combineTwoDisorderNodeToOrder (ListNode node1, ListNode node2) {
// write code here
List<ListNode> lists = new ArrayList<>();
getListNodeToLists(node1, lists);
getListNodeToLists(node2, lists);
lists.sort((ListNode a, ListNode b) -> {
return a.val - b.val;
});
return getSortListNode(lists);
}
public void getListNodeToLists(ListNode head, List<ListNode> lists) {
while(head != null) {
ListNode next = head.next;
head.next = null;
lists.add(head);
head = next;
}
}
public ListNode getSortListNode(List<ListNode> lists) {
ListNode head = new ListNode(0);
ListNode cur = head;
for (int i = 0; i < lists.size(); i++) {
cur.next = lists.get(i);
cur = cur.next;
}
return head.next;
}
}
编程题3AC
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param scenicspot int整型
* @return long长整型
*/
public long tourismRoutePlanning (int scenicspot) {
// write code here
if (scenicspot == 1)
return 1L;
if (scenicspot == 2)
return 2L;
long[] dp = new long[scenicspot];
dp[0] = 1L; dp[1] = 2L;
for (int i = 2; i < scenicspot; i++)
dp[i] = dp[i-1] + dp[i-2];
return dp[scenicspot - 1];
}
}
三道题的难度都很简单,不知道这个岗位是不是不招人了