Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 53b6a7a

Browse files
committed
更新
1 parent d7b06d6 commit 53b6a7a

8 files changed

+243
-4
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// 2021秋招-网易互联网笔试
2+
3+
// 2.小明在一条直线上执行任务,需要在坐标0的位置和坐标a的位置之间需要从0移动到a,
4+
// 每移动1个单位坐标,小明携带的仪器需要耗费对应1个单位的能量。
5+
// 携带的仪器最多可装b个单位能量,初始时仪器是满能量。坐标0和a之间有一处坐标f的位置
6+
// 可以给仪器充能。现在小明从0移动至a或者从a移动至0都算一次行动。
7+
// 请问小明从0出发,希望完成k次行动,最少需要在f坐标处充能多少次。
8+
// 输入描述:一行4个空格隔开的数字a、b、f、k。
9+
// i<f<a=10^6;1<=b<=10^9;1<=k<=10^4。
10+
function solveProblem2(arr) {
11+
const a = arr[0], b = arr[1], f = arr[2], k = arr[3];
12+
let res = -1, resTimes = 0, times = 0,
13+
of = f, fa = a - f, oa = a, last = b;
14+
while (true) {
15+
if (last - of >= 2*fa) {
16+
times++;
17+
last = last - oa;
18+
if (times === k) {
19+
res = resTimes;
20+
break;
21+
}
22+
} else if (last - of >= fa) {
23+
times++;
24+
if (times === k) {
25+
res = resTimes;
26+
break;
27+
} else {
28+
resTimes++;
29+
last = b - fa;
30+
}
31+
} else if (last >= of) {
32+
times++;
33+
resTimes++;
34+
last = b - fa;
35+
if (times === k) {
36+
res = resTimes;
37+
break;
38+
}
39+
} else if (last < of) break;
40+
41+
if (last - fa >= 2*of) {
42+
times++;
43+
last = last - oa;
44+
if (times === k) {
45+
res = resTimes;
46+
break;
47+
}
48+
} else if (last - fa >= of) {
49+
times++;
50+
if (times === k) {
51+
res = resTimes;
52+
break;
53+
} else {
54+
resTimes++;
55+
last = b - of;
56+
}
57+
} else if (last >= fa) {
58+
times++;
59+
resTimes++;
60+
last = b - of;
61+
if (times === k) {
62+
res = resTimes;
63+
break;
64+
}
65+
} else if (last < fa) break;
66+
}
67+
return res
68+
}
69+
70+
console.log(solveProblem2([6, 9, 2, 4]));

‎Topics/招聘题目/2021秋招-去哪儿网校招-笔试编程题.js renamed to ‎Topics/招聘/2021秋招-去哪儿网笔试.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// 2021秋招-去哪儿网校招-笔试编程题
1+
// 2021秋招-去哪儿网笔试
22

33
// 大数相加:以字符串的形式读入两个较大的数字,编写一个函数计算它们的和,以字符串形式返回。
44
function solveMeFirst1(number1, number2) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// 2021秋招-富途一面
2+
3+
// 2.输入:[['red', 'green'], ['a1', 'a2'], ['b1', 'b2']]
4+
// 编写一个函数,要求输出:['red-a1-b1', 'red-a1-b2', 'red-a2-b1', 'red-a2-b2',
5+
// 'green-a1-b1', 'green-a1-b2','green-a2-b1','green-a2-b2']
6+
7+
const arr = [['red', 'green'], ['a1', 'a2'], ['b1', 'b2']];
8+
9+
// 方法一:
10+
function create(arr) {
11+
let res = arr.reduce(
12+
(a, b) => a.map(aItem => b.map(bItem => aItem + '-' + bItem)).reduce((a, b) => [...a, ...b])
13+
);
14+
return res
15+
}
16+
function create(arr) {
17+
let res;
18+
res = arr.reduce(function (a, b) {
19+
let res = a.map(function (aItem) {
20+
let res = b.map(function (bItem) {
21+
console.log(aItem + '-' + bItem)
22+
return aItem + '-' + bItem
23+
})
24+
return res
25+
})
26+
console.log(res)
27+
res = res.reduce(function (a, b) {
28+
return [...a, ...b]
29+
})
30+
return res
31+
})
32+
return res
33+
}
34+
35+
// 方法二:
36+
function combine(arr) {
37+
const res = [];
38+
function helper(chunkIndex, prev) {
39+
let chunk = arr[chunkIndex];
40+
let isLast = chunkIndex === arr.length - 1;
41+
for (let val of chunk) {
42+
let cur = prev.concat(val);
43+
if (isLast) {
44+
// 如果已经处理到数组的最后一项了 则把拼接的结果放入返回值中
45+
res.push(cur);
46+
} else {
47+
helper(chunkIndex + 1, cur);
48+
}
49+
}
50+
}
51+
// 从属性数组下标为 0 开始处理
52+
// 并且此时的 prev 是个空数组
53+
helper(0, []);
54+
return res;
55+
}

‎Topics/招聘题目/2021秋招-小红书校招-笔试编程题.js renamed to ‎Topics/招聘/2021秋招-小红书笔试.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// 2021秋招-小红书校招-笔试编程题
1+
// 2021秋招-小红书笔试
22

33
// 1.获取 URL 中 key 对应的 value 值
44
function solveMeFirst1(url, key) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 2021秋招-深信服一面
2+
3+
// 写一个过滤函数,输入一个树和一个字符串:
4+
tree = [
5+
{'name': 'A'},
6+
{'name': 'B', 'child':[
7+
{'name': 'A'},
8+
{'name': 'AA'}
9+
]}
10+
]
11+
// 当输入字符串为'A'时,输出为

‎Topics/招聘题目/2021秋招-网易互联网校招-笔试编程题.js renamed to ‎Topics/招聘/2021秋招-网易互联网笔试.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// 2021秋招-网易互联网校招-笔试编程题
2-
// 2.数字分解
1+
// 2021秋招-网易互联网笔试
32

3+
// 2.数字分解
44
// 通过 36%
55
function solveProblem2(num1, num2) {
66
if (num2 / num1 < 2) return -1
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// 2021秋招-金山云笔试
2+
3+
// 2.一只聪明的老鼠发现了一个三角形的奶酪迷宫。这个迷宫有若干个小房间,每个小房间有若干
4+
// 块大小相等的小奶酪(每个房间至少有一块奶酪)。奶酪迷宫的构造如下:(1)奶酪迷官一共
5+
// 有 N 行,第 1 行有一个小房间,第 2 行有两个房间,第 3 行有三个小房间,...第N行有N个小房间。
6+
// (2)所有的小房间都是从第1列开始进行排列的。(3)奶酪迷宫的入口是第 1 行的那个小房间。
7+
// (4)由于奶酪迷宫的特殊构造,小老鼠进入一个房间后,不允许回退到上一层的房间,也不允许
8+
// 走到左边的房间,只允许走到右边或者下面的房间。(5)在奶酪迷宫的最后一层,每个房间都有
9+
// 一扇通往迷宫出口的门,且最后一层的小房间没有通往左边和右边小房间的门。现在
10+
// 小老鼠已经知道了每个小房间里面有多少块小奶酪,它找到了一条可以从入口走到出囗且可以
11+
// 得到最多小奶酪的路径。你能不能编写一个程序,输出小老鼠最多可以得到多少块小奶酪呢?
12+
13+
// 单组输入,第 1 行输入 1 个正整数 N,表示奶酪迷宫的行数,N <= 100。
14+
// 接下来 N 行,第 1 行有 1 个正整数,表示第 1 行 1 个小房间的小奶酪数;
15+
// 第 2 行有 2 个正整数,表示第 2 行 2 个小房间的小奶略数;...;
16+
// 第 N 行有 N 个正整数,表示第 N 行 N 个小房间的小奶酪数。
17+
// 每个房间的小奶酪数均不超过 1000。每一行两个正整数之间用英文的空格隔开。
18+
19+
// 4
20+
21+
// 2
22+
// 1 2
23+
// 1 1 1
24+
// 9 1 1 1
25+
26+
// 1 1
27+
// 2 1
28+
// 3 2
29+
// 4 5
30+
// 5
31+
32+
let num = 0;
33+
const max = Math.max(...arr)
34+
for (let i = 1; i < arr.length; i++) {
35+
if (max > arr[i]) num++
36+
}
37+
38+
let max = 1;
39+
for (let i = 0; i < now.length; i++) {
40+
let num = 1;
41+
if (i - 1 >= 0) num += test(i, 'left')
42+
if (i + 1 < now.length - 1) num += test(i, 'right')
43+
max = Math.max(max, num)
44+
}
45+
function test(index, to) {
46+
let num = 0;
47+
if (to === 'left' && now[index] >= now[index - 1]) {
48+
num++;
49+
if (index - 1 >= 0) num += test(index - 1, 'left');
50+
}
51+
if (to === 'right' && now[index] >= now[index + 1]) {
52+
num++;
53+
if (index + 1 < now.length - 1) num += test(index + 1, 'right');
54+
}
55+
return num
56+
}

‎Topics/排列组合.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// 排列
2+
function queue(arr, size) {
3+
if (size > arr.length) return;
4+
const allResult = [];
5+
6+
(function (arr, size, result) {
7+
const arrLen = arr.length;
8+
if (result.length === size) allResult.push(result);
9+
else {
10+
for (let i = 0; i < arrLen; i++) {
11+
const newArr = [].concat(arr);
12+
const curItem = newArr.splice(i, 1);
13+
arguments.callee(newArr, size, [].concat(result, curItem));
14+
}
15+
}
16+
})(arr, size, []);
17+
18+
return allResult;
19+
}
20+
console.log(queue([1, 2, 3], 3)); // A(3, 3) = 3! = 6
21+
console.log(queue([1, 2, 3, 4], 3)); // A(4, 3) = 4! / 1! = 24
22+
23+
// 组合
24+
function choose(arr, size) {
25+
const allResult = [];
26+
27+
(function (arr, size, result) {
28+
const arrLen = arr.length;
29+
if (size > arrLen) return;
30+
if (size === arrLen) allResult.push([].concat(result, arr));
31+
else {
32+
for (let i = 0; i < arrLen; i++) {
33+
const newResult = [].concat(result);
34+
newResult.push(arr[i]);
35+
if (size === 1) allResult.push(newResult);
36+
else {
37+
const newArr = [].concat(arr);
38+
newArr.splice(0, i + 1);
39+
arguments.callee(newArr, size - 1, newResult);
40+
}
41+
}
42+
}
43+
})(arr, size, []);
44+
45+
return allResult;
46+
}
47+
console.log(choose([1, 2, 3, 4, 5], 3)); // C(5,3) = A(5,3) / A(3,3) = 10

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /