article / aiznoyer
2023.10.26 shopee虾皮大数据开发工程师笔试
Shopee虾皮笔试
10单选+5多选
TCP三次握手、线程、设计模式、平衡二叉树、数组和链表的区别、左中序遍历建树、栈进出
SQL:group by having的使用、binlog日志特点、join的用法
3编程
(1)String 非负大数相乘(Solution)
java
public static String Solution(String num1, String num2) {
int m = num1.length();
int n = num2.length();
int[] product = new int[m + n]; // 保存乘积的数组
// 从个位数开始逐位相乘
for (int i = m - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
int digit1 = num1.charAt(i) - '0';
int digit2 = num2.charAt(j) - '0';
int currProduct = digit1 * digit2;
// 将当前位的乘积结果加到对应的位置
int p1 = i + j; // 十位数的位置
int p2 = i + j + 1; // 个位数的位置
int sum = currProduct + product[p2];
// 更新十位数和个位数
product[p1] += sum / 10;
product[p2] = sum % 10;
}
}
// 构建结果字符串
StringBuilder sb = new StringBuilder();
for (int digit : product) {
if (sb.length() != 0 || digit != 0) {
sb.append(digit);
}
}
return sb.length() == 0 ? "0" : sb.toString();
}
(2)反转语句(Solution)
将hello world反转成olleh dlrow,太简单了就不多说了
(3)层次遍历格式转换(ACM)
输入{3,9,20,#,#,15,7}
输出[[3],9,20,15,7]
java
import java.util.Objects;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// {3,9,20,#,#,15,7}
String str = sc.nextLine();
str = str.substring(1, str.length() - 1);
String[] str2 = str.split(",");
int count = 0;
while((int)Math.pow(2, count) - 1 < str2.length) count++;
StringBuilder result = new StringBuilder();
result.append("[");
for(int i = 1; i <= count; i++) {
result.append("[");
for (int j = 0; j < Math.pow(2, i - 1) && j + (int)Math.pow(2, i - 1) - 1 < str2.length; j++) {
if(!Objects.equals(str2[j + (int) Math.pow(2, i - 1) - 1], "#")){
result.append(str2[j + (int)Math.pow(2, i - 1) - 1]);
if(j + 1 < Math.pow(2, i - 1)) result.append(",");
}
}
if(i + 1 <= count)result.append("],");
else result.append("]");
}
result.append("]");
System.out.println(result.toString());
}
}