-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path43-字符串相乘.html
54 lines (44 loc) · 1.09 KB
/
43-字符串相乘.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>leetcode--字符串相乘</title>
</head>
<body>
<script>
/**
* @param {string} num1
* @param {string} num2
* @return {string}
*/
var multiply = function (num1, num2) {
if (num1.charAt(0) == 0 || num2.charAt(0) == 0) {
return '0'
}
let a = num1.split('')
let b = num2.split('')
let c = []
for (let i = 0; i < a.length; i++) {
for (let j = 0; j < b.length; j++) {
c[i + j] ? (c[i + j] += a[i] * b [j]) : (c[i + j] = a[i] * b [j])
}
}
for (let index = c.length; index > 0; index--) {
if (c[index] > 9) {
c[index - 1] += (c[index] / 10 | 0)
c[index] %= 10
}
}
let str = c.join('')
return str
};
multiply('1132', '1323')
cf(1132, 1323)
function cf(a, b) {
console.log(a * b , '8888')
}
</script>
</body>
</html>