MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / carry

Function carry

javascript/0066-plus-one.js:17–26  ·  view source on GitHub ↗
(digits)

Source from the content-addressed store, hash-verified

15var add = (digits) => (digits[digits.length - 1] += 1);
16
17var carry = (digits) => {
18 for (let digit = digits.length - 1; 0 < digit; digit--) {
19 /* Time O(N) */
20 const canCarry = digits[digit] === 10;
21 if (!canCarry) break;
22
23 digits[digit] = 0;
24 digits[digit - 1] += 1;
25 }
26};
27
28const addLeading = (digits) => {
29 const canCarry = digits[0] === 10;

Callers 1

plusOneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected