Skip to content

Commit 2639c16

Browse files
committed
https://leetcode.cn/problems/broken-calculator
1 parent 521dafe commit 2639c16

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/broken-calculator
14+
1315
https://leetcode.cn/problems/pairs-with-sum-lcci/
1416

1517
https://leetcode.cn/problems/count-number-of-bad-pairs/

broken-calculator/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default function brokenCalc(startValue: number, target: number): number {
2+
if (target <= startValue) return startValue - target;
3+
if (target % 2 == 0) return 1 + brokenCalc(startValue, target / 2);
4+
else return 1 + brokenCalc(startValue, target + 1);
5+
}

0 commit comments

Comments
 (0)