1面試的總結的經驗是對輸入和輸出的IO模板要熟悉
2輸出的結果的運行
3
1假定操作系統是採用的是32位整數的爲進程號的。當創建新的進程的時候需要找到最小的未使用的是進程ID
輸入:
一行是表示的n 不超過是2^20
接下來是的n中已經存在的id正整數的2^31 不保證排序
輸入實例:
5
1
2
3
4
6
輸出結果:
5
/**
* Copyright (C), 2018-2020
* FileName: Main
* Author: xjl
* Date: 2020/7/4 14:55
* Description: 測試案例
*/
package IO_Template;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int test = test();
System.out.println(test);
}
public static int test() {
Scanner sc = new Scanner(System.in);
//輸入的第一行
int n = sc.nextInt();
sc.nextLine();
int result = 1;
ArrayList<Integer> list = new ArrayList<>();
//存放數據
for (int i = 0; i < n; i++) {
int num = sc.nextInt();
list.add(num);
}
//尋找結果
for (int i = 1; i <= n; i++) {
if (!list.contains(i)) {
return i;
}
}
return 0;
}
}
2 輸入一個字符串首位相連,身爲一個環 問是否能從一個切點中的切斷後產生一個迴文 ,可以的話輸出Yes 否則是輸出No
輸入:字符串
輸入的實例:aab
輸出:Yes
public static void test1() {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
//輸入
String str = sc.nextLine();
//處理
boolean result = ishiuwen(str);
//輸出
if (result) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
private static boolean ishiuwen(String str) {
int length = str.length();
String result = str + str;
for (int i = 0; i < length; i++) {
String s = result.substring(i, i + length);
if (ishiu(s)) {
return true;
}
}
return false;
}
private static boolean ishiu(String s) {
int start = 0;
int end = s.length() - 1;
while (start <= end) {
if (s.charAt(start) != s.charAt(end)) {
return false;
}
start++;
end--;
}
return true;
}
3輸入一個整數 把一個每位數組拆開,然後組合成爲其他的數據,並在這裏集合中的找到一個比n小的,但是是集合紅的最大的一個數據 比如:15234 可以拆分爲 1 2 3 4 5 然後組合比15234要小的數組就 但是集合中最大的一個 如果不存在輸入Not found
輸入實例:
153
輸出135
11
Not Found