二进制求和

This commit is contained in:
yi-ge 2020-06-23 13:52:47 +08:00
parent fb6131a64e
commit e5a2f13ee2
3 changed files with 20 additions and 0 deletions

View File

@ -448,6 +448,11 @@ LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重
- LeetCode 15. 三数之和 <https://leetcode-cn.com/problems/3sum/>
- LintCode 57. 三数之和 <https://www.lintcode.com/problem/3sum/description>
- [二进制求和](src/math/add-binary.js)
- LeetCode 67. 二进制求和 <https://leetcode-cn.com/problems/add-binary/>
- LeetCode 408. 二进制求和 <https://www.lintcode.com/problem/add-binary/description>
## 堆
- [超级丑数](src/stack/super-ugly-number.js)【未完成】

9
src/math/add-binary.js Normal file
View File

@ -0,0 +1,9 @@
/**
* @param {string} a
* @param {string} b
* @return {string}
*/
export const addBinary = function (a, b) {
// eslint-disable-next-line no-undef
return (BigInt('0b' + a) + BigInt('0b' + b)).toString(2)
}

View File

@ -0,0 +1,6 @@
import { addBinary } from '../../src/math/add-binary'
test('二进制求和', () => {
expect(addBinary('11', '1')).toEqual('100')
expect(addBinary('1010', '1011')).toEqual('10101')
})