华为秋招面试基本流程:
1. 询问笔试题
2. 简历上的项目介绍
3. 手撕代码题
我的三道笔试题:
一、开心消消乐
把字符串中相邻相同的字符串消除掉,消除后相邻的继续消除
abaabc => ac
这道题用栈
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
Stack<Character> stack = new Stack<>();
int n = s.length();
for (int i = 0; i < n; i++) {
if (stack.isEmpty() || stack.peek() != s.charAt(i)){
stack.push(s.charAt(i));
continue;
} else {
stack.pop();
}
}
StringBuffer sb = new StringBuffer();
while (!stack.isEmpty()) {
sb.append(stack.pop());
}
String res = sb.reverse().toString();
System.out.println(res);
}
}
二、天平平衡的