8000 Merge branch 'main' of https://github.com/Tahirc1/LeetcodeJs · Tahirc1/LeetcodeJs@dc88012 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc88012

Browse files
committed
2 parents 70686f1 + f36f34c commit dc88012

File tree

5 files changed

+102
-14
lines changed

5 files changed

+102
-14
lines changed
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
var removeNthFromEnd = function(head, n) {
2-
let count = 0
3-
let m = head
2+
let count = 0 // counter
3+
let m = head // store head node
4+
// count no. of nodes
45
while(head != null){
5-
head = head.next
6-
count++
6+
head = head.next // travel to next node
7+
count++ // increment counter
78
}
9+
// create new ListNode
810
let k = new ListNode(0)
9-
let ans = k
11+
let ans = k // store head of k list
1012
for(let i = 0 ; i < count ; i++){
13+
// if i is not nth node from end we add that node to k list
1114
if(i != count - n){
1215
k = k.next = new ListNode(m.val)
1316
}
14-
m = m.next
17+
m = m.next // travel to next node
1518
}
1619
return ans.next
17-
};
20+
};

11-20/20. Valid Parentheses.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
var isValid = function(s) {
2-
let l = s.length+1;
2+
let l = s.length+1; // store length+1
3+
// while l is not equal to s.length
34
while(l !== s.length) {
4-
l = s.length;
5+
l = s.length; // store s.length in l
6+
// when we replace () or {} or [] with ''
7+
// the length of string s is reduced
58
s = s.replaceAll('()','');
69
s = s.replaceAll('{}','');
710
s = s.replaceAll('[]','');
11+
// if nothing is replaced l equals s.length
12+
// thus ending the while loop
813
}
14+
// if s.length becomes 0 thus string had valid parentheses
915
return s.length === 0;
10-
}
16+
}

21-30/21. Merge Two Sorted Lists.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
var mergeTwoLists = function(list1, list2) {
2+
// add the list node to a variable
23
let l = new ListNode(0);
34
let head = l
5+
// create a while loop and check if the argument (list1 and list2) is not empty
46
while(list1 != null && list2 != null){
7+
// if the value of list1 is less than list2
58
if(list1.val < list2.val){
9+
//add the value to the node list of 1
610
l.next = list1
711
list1 = list1.next
812
}else{
13+
// if not add the value to the node list of 2
914
l.next = list2
1015
list2 = list2.next
1116
}
17+
18+
//move on to the next node
1219
l = l.next
1320
}
21+
22+
//add the remaining node values to the merged list
1423
if (list1 == null) {
1524
l.next = list2;
1625
}
1726
else {
1827
l.next = list1;
1928
}
29+
30+
//return the combined sorted list
2031
return head.next
2132
};

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# LeetcodeJs
22
Library for LeetCode Questions solved in JS with comments
33

4-
Anyone can add Leetcode solutions in JS or add comments to existing solutions
4+
Anyone can add Leetcode solutions in JS or add comments to existing solutions\
5+
UNSOLVED.md contains the unsolved problems
56

67
Follow naming convention \
7-
'Question Number'+'. '+'Question Name'\
8-
\
9-
Add ur Name and Socials on top 2 lines as a comment
8+
- 'Question Number'+'. '+'Question Name'\
9+
10+
Add your Name and Socials on top 2 lines as a comment

UNSOLVED.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## Unsolved Problems
2+
**LeetCode problems to be solved**
3+
<details>
4+
<summary>1-10</summary>
5+
10. Regular Expression Matching
6+
</details>
7+
<details>
8+
<summary>11-20</summary>
9+
16. 3Sum Closest <br>
10+
18. 4Sum
11+
</details>
12+
<details>
13+
<summary>21-30</summary>
14+
22. Generate Parentheses <br>
15+
30. Substring with Concatenation of All Words
16+
</details>
17+
<details>
18+
<summary>31-40</summary>
19+
31. Next Permutation <br>
20+
32. Longest Valid Parentheses <br>
21+
37. Sudoku Solver <br>
22+
39. Combination Sum <br>
23+
40. Combination Sum II
24+
</details>
25+
<details>
26+
<summary>41-50</summary>
27+
42. Trapping Rain Water <br>
28+
44. Wildcard Matching <br>
29+
46. Permutations <br>
30+
47. Permutations II
31+
</details>
32+
<details>
33+
<summary>51-60</summary>
34+
51. N-Queens <br>
35+
52. N-Queens II <br>
36+
56. Merge Intervals <br>
37+
59. Spiral Matrix II <br>
38+
60. Permutation Sequence
39+
</details>
40+
<details>
41+
<summary>61-70</summary>
42+
63. Unique Paths II <br>
43+
64. Minimum Path Sum
44+
</details>
45+
<details>
46+
<summary>71-80</summary>
47+
71. Simplify Path <br>
48+
72. Edit Distance <br>
49+
76. Minimum Window Substring
50+
</details>
51+
<details>
52+
<summary>81-90</summary>
53+
84. Largest Rectangle in Histogram <br>
54+
85. Maximal Rectangle <br>
55+
87. Scramble String <br>
56+
89. Gray Code <br>
57+
90. Subsets II
58+
</details>
59+
<details>
60+
<summary>91-100</summary>
61+
91. Decode Ways <br>
62+
93. Restore IP Addresses <br>
63+
95. Unique Binary Search Trees II <br>
64+
96. Unique Binary Search Trees <br>
65+
97. Interleaving String <br>
66+
99. Recover Binary Search Tree
67+
</details>

0 commit comments

Comments
 (0)
0