小米沒有進行筆試直接發起了面試。
整體感覺還挺好的,面試官很和善。
- 上來先是自我介紹
- 問項目
- 問在Android開發中遇到的問題及解決方案
- 對工作地的選擇
- 問未來希望的發展方向,上層應用還是偏 framework 的(介紹了下工作地等)
- finally final finalize 的區別 講一下
- final可以修飾什麼 作用等
- JVM中 堆和棧的區別
- 堆和棧的內存可見性
- Java 中的四種引用方式,強引用弱引用等
- Android activity的四種啓動模式
- 事件分發機制
- 還有些基礎知識不記得了
- 手撕代碼1 實現一個單鏈表的反轉,自定義鏈表類型,不要使用遞歸(自己定義輸入,並進行輸出檢測,也就是自己先生成一個鏈表再去翻轉)
- 手撕代碼2 實現atoi函數,輸入string,輸出int(字符串可能存在字符,可能超過int最大長度,要求判斷特殊情況。)
- 反問環節
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Stack <Node> stack = new Stack<>();//使用棧
int temp = in.nextInt();
Node head = new Node(temp);
Node head1 = head;//保存頭結點
for(int i = 1 ; i < n; i++ ){
int temp1 = in.nextInt();
Node temp2 = new Node(temp1);
head1.next = temp2;
head1 = head1.next;
}//完成初始鏈表建立
in.close();
for(int i = 0 ; i < n;i++ ){
stack.push(head);
head = head.next;
}//插入棧中
Node out = new Node(100);
Node out1 = out;
while(!stack.isEmpty()){
out.next = stack.pop();
out = out.next;
}//彈棧,建立輸出鏈表
out.next =null;
out1 = out1.next;
for(int i = 0 ; i < n;i++ ){
System.out.println(out1.val);
out1 = out1.next;
}//打印
}
static class Node {//節點類
int val;
Node next;
public Node(int val){
this.val = val;
}
}
//字符串轉成int
public static int atoi(String string){
char ato = string.charAt(0);//判斷是不是負數
int bigger0 = 1;
if(ato == '-')
bigger0 = -1;
long length = string.length();
if(length > 11){ //int max=2147483647 int min=-2147483648 算上符號位最長11位
System.out.println("超過int型最大長度");
return -1;
}
int value = 0;
int time = 0;
if(bigger0 == -1)
time = 1;
while(time <= length - 1){
if(string.charAt(time)> '9' ||string.charAt(time)<'0'){
System.out.println("含有非數字字符");
return -1;
}else{
value = (string.charAt(time)-'0') + 10 * vaule;
//這個地方這麼寫肯定情況是不全的,我還沒寫完,面試官說時間差不多,沒在繼續考慮
if(vaule > Integer.max() / 10){
if(length - 1 -time > 1){
System.out.println("超過int型最大值");
return -1;
}
}
}
time++;
}
return vaule * bigger0;
}
}
第一個翻轉鏈表寫完通過了,我說還可以用頭插法,只不過感覺棧簡單一點,他說其實是希望我用頭插法寫的,說他看一下代碼,然後就讓我寫第二題,第二題最後沒有輸入用例去調試,只是寫了個函數。寫的不全面。