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 a48aa75

Browse files
committed
添加题目
1 parent 60ddb44 commit a48aa75

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

‎Algorithms/查找和排序.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
查找和排序都是在程序设计中经常用到的算法。查找相对而言较为简单,排序比查找要复杂一些。
22
- 查找有顺序查找、二分查找、哈希表查找、二叉排序树查找等;
3-
- 排序有插入排序、冒泡排序、归并排序、快速排序等。
3+
- 排序有选择排序、希尔排序、插入排序、冒泡排序、归并排序、快速排序等。

‎Topics/大数相加.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// 2021秋招-去哪儿网校招-笔试编程题
2+
// 以字符串的形式读入两个较大的数字,编写一个函数计算它们的和,以字符串形式返回。
3+
function add(number1, number2) {
4+
5+
const longArr = [], shortArr = [];
6+
if (number1.length > number2.length) {
7+
for (const x of number1) longArr.push(x)
8+
for (const y of number2) shortArr.push(y)
9+
} else {
10+
for (const x of number1) shortArr.push(x)
11+
for (const y of number2) longArr.push(y)
12+
}
13+
14+
const max = longArr.length, min = shortArr.length;
15+
let add10 = 0, res = '', num, num1, num2;
16+
for (let i = 0; i < max; i++) {
17+
if (i < min) {
18+
num1 = Number(longArr[longArr.length - i - 1]);
19+
num2 = Number(shortArr[shortArr.length - i - 1]);
20+
} else {
21+
num1 = Number(longArr[longArr.length - i - 1]);
22+
num2 = 0;
23+
}
24+
num = num1 + num2 + add10;
25+
add10 = 0;
26+
if ( i !== max - 1 && num >= 10) {
27+
num = num - 10;
28+
add10 = 1;
29+
}
30+
res = num + res;
31+
}
32+
return res;
33+
}
34+
console.log(add('589465849568', '669784652318'));
35+
console.log(589465849568 + 669784652318);

0 commit comments

Comments
(0)

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