Skip to content

Commit b6281d8

Browse files
committed
ts-3: added non-null assertions to inform typescript checks
1 parent e6a13e9 commit b6281d8

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

typescript/Linked Lists/palindromic_linked_list.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ function palindromicLinkedList(head: LLNode): boolean {
1919
let ptr1 = head, ptr2 = secondHead;
2020
let res = true;
2121
while (ptr2) {
22-
if (ptr1.val !== ptr2.val) {
22+
if (ptr1!.val !== ptr2.val) {
2323
res = false;
2424
}
25-
ptr1 = ptr1.next, ptr2 = ptr2.next;
25+
ptr1 = ptr1!.next, ptr2 = ptr2.next;
2626
}
2727
return res;
2828
}
@@ -45,8 +45,8 @@ function findMiddle(head: LLNode): LLNode {
4545
let slow: LLNode = head;
4646
let fast: LLNode = head;
4747
while (fast && fast.next) {
48-
slow = slow.next;
49-
fast = fast.next.next;
48+
slow = slow!.next;
49+
fast = fast.next!.next;
5050
}
5151
return slow;
5252
}

typescript/Linked Lists/remove_kth_last_node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ function removeKthLastNode(head: LLNode, k: number): LLNode {
2828
// k nodes behind.
2929
while (leader.next !== null){
3030
leader = leader.next;
31-
trailer = trailer.next;
31+
trailer = trailer!.next;
3232
}
3333
// Remove the kth node from the end.
34-
trailer.next = trailer.next.next;
34+
trailer!.next = trailer!.next!.next;
3535
return dummy.next;
3636
}

0 commit comments

Comments
 (0)