Content-Length: 368688 | pFad | http://github.com/GameOfCode64/DSA-JavaScript/commit/cbf3bf6840f8d87b47201796cdc8736b1f93028c

78 day 8 complate with array · GameOfCode64/DSA-JavaScript@cbf3bf6 · GitHub
Skip to content

Commit cbf3bf6

Browse files
committed
day 8 complate with array
1 parent fac0849 commit cbf3bf6

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

Array/day7.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// * Q5, Search Insert Position
66
// * Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
77
// * You must write an algorithm with O(log n) runtime complexity
8-
98
// * Input: nums = [1,3,5,6], target = 5 , Output: 2
109
// * Input: nums = [1,3,5,6], target = 2 , Output: 1
1110

Array/day8.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ! DSA in JavaScript day 5
2+
3+
// Todo: Topic Array
4+
5+
// * Q6, Plus One
6+
7+
// * You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. Increment the large integer by one and return the resulting array of digits.
8+
9+
// * Input: digits = [1,2,3], [4,3,2,1], [9]
10+
// * Output: [1,2,4]
11+
// * Explanation: The array represents the integer 123.
12+
// * Incrementing by one gives 123 + 1 = 124.
13+
// * Thus, the result should be [1,2,4].
14+
15+
// Todo: My Answer (Wrong Answer)
16+
function plusOne1(integer) {
17+
if (integer.length - 1 !== 9) {
18+
let num = "";
19+
for (let i = 0; i < integer.length; i++) {
20+
num += integer[i];
21+
}
22+
num = parseInt(num);
23+
return num + 1;
24+
}
25+
}
26+
27+
console.log(plusOne1([9]));
28+
console.clear();
29+
30+
function plusOne(digits) {
31+
for (let i = digits.length - 1; i >= 0; i--) {
32+
if (digits[i] < 9) {
33+
digits[i]++;
34+
return digits;
35+
}
36+
digits[i] = 0;
37+
}
38+
digits.unshift(1);
39+
return digits;
40+
}
41+
console.log(plusOne([1, 2, 3]));

Array/tempCodeRunnerFile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mango

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/GameOfCode64/DSA-JavaScript/commit/cbf3bf6840f8d87b47201796cdc8736b1f93028c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy