当前位置: 首页 > 面试经验 >

20240825蚂蚁后端笔试前两题ac

优质
小牛编辑
80浏览
2024-08-25

20240825蚂蚁后端笔试前两题ac

  1. (a==b)&&(d==0 || a>0)为YES
  2. dfs预处理一份全部的好数列表,对每次询问二分答案
static int[] goodNums = new int[5680000];
static int p = 0;

static {
	for (int i = 1; i <= 9; i++) {
		dfs(0, i, 0, 0);
	}
	goodNums[p++] = 1023456789;
}

static void dfs(int pos, int n, int mask, int curNum) {
	if (pos == n) {
		goodNums[p++] = curNum;
		return;
	}
	for (int i = 0; i <= 9; i++) {
		if (i == 0 && pos == 0) {
			continue;
		}
		if (((mask >> i) & 1) == 0) {
			dfs(pos + 1, n, mask | (1 << i), curNum * 10 + i);
		}
	}
}

 类似资料: