Skip to content

Commit 8e7139e

Browse files
committed
feat: add Merge Two Sorted Lists in Racket
1 parent abf33f3 commit 8e7139e

File tree

2 files changed

+49
-34
lines changed

2 files changed

+49
-34
lines changed

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@ https://neetcode.io/roadmap
44

55
### NeetCode
66

7-
| # | Title | Difficulty | Solution | Category |
8-
| --- | ------------------------------------------------------------------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------- | ---------------- |
9-
| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | Easy | [ts](./TypeScript/217.contains-duplicate.ts) | Arrays & Hashing |
10-
| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | Easy | [ts](./TypeScript/242.valid-anagram.ts) | Arrays & Hashing |
11-
| 242 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [ts](./TypeScript/1.two-sum.ts) | Arrays & Hashing |
12-
| 49 | [Group Anagrams](https://leetcode.com/problems/two-sum/) | Medium | [ts](./TypeScript/49.group-anagrams.ts) | Arrays & Hashing |
13-
| 347 | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/) | Medium | [ts](./TypeScript/347.top-k-frequent-elements.ts) | Arrays & Hashing |
14-
| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | Medium | [ts](./TypeScript/238.product-of-array-except-self.ts) | Arrays & Hashing |
15-
| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | Medium | [ts](./TypeScript/36.valid-sudoku.ts) | Arrays & Hashing |
16-
| 659 | [Encode and Decode Strings](https://www.lintcode.com/problem/659/) | Medium | [ts](./TypeScript/659.encode-and-decode-strings.ts) | Arrays & Hashing |
17-
| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/) | Medium | [ts](./TypeScript/128.longest-consecutive-sequence.ts) | Arrays & Hashing |
18-
| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | Easy | [ts](./TypeScript/125.valid-palindrome.ts) | Two Pointers |
19-
| 167 | [Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | Medium | [ts](./TypeScript/167.two-sum-ii-input-array-is-sorted.ts) | Two Pointers |
20-
| 15 | [3Sum](https://leetcode.com/problems/3sum/) | Medium | [ts](./TypeScript/15.3sum.ts) | Two Pointers |
21-
| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | Medium | [ts](./TypeScript/11.container-with-most-water.ts) | Two Pointers |
22-
| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) | Hard | [ts](./TypeScript/42.trapping-rain-water.ts) | Two Pointers |
23-
| 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [ts](./TypeScript/20.valid-parentheses.ts) | Stack |
24-
| 155 | [Min Stack](https://leetcode.com/problems/min-stack/) | Medium | [ts](./TypeScript/155.min-stack.ts) | Stack |
25-
| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | Medium | [ts](./TypeScript/150.evaluate-reverse-polish-notation.ts) | Stack |
26-
| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/) | Medium | [ts](./TypeScript/22.generate-parentheses.ts) | Stack |
27-
| 739 | [Daily Temperatures](https://leetcode.com/problems/daily-temperatures/) | Medium | [ts](./TypeScript/739.daily-temperatures.ts) | Stack |
28-
| 853 | [Car Fleet](https://leetcode.com/problems/car-fleet/) | Medium | [ts](./TypeScript/853.car-fleet.ts) | Stack |
29-
| 84 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | Hard | [ts](./TypeScript/84.largest-rectangle-in-histogram.ts) | Stack |
30-
| 704 | [Binary Search](https://leetcode.com/problems/binary-search/) | Easy | [ts](./TypeScript/704.binary-search.ts) | Binary Search |
31-
| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) | Medium | [ts](./TypeScript/74.search-a-2d-matrix.ts) | Binary Search |
32-
| 875 | [Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/) | Medium | [ts](./TypeScript/875.koko-eating-bananas.ts) | Binary Search |
33-
| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | [ts](./TypeScript/153.find-minimum-in-rotated-sorted-array.ts) | Binary Search |
34-
| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | Medium | [ts](./TypeScript/33.search-in-rotated-sorted-array.ts) | Binary Search |
35-
| 981 | [Time Based Key-Value Store](https://leetcode.com/problems/time-based-key-value-store/) | Medium | [ts](./TypeScript/981.time-based-key-value-store.ts) | Binary Search |
36-
| 121 | [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | Easy | [ts](./TypeScript/121.best-time-to-buy-and-sell-stock.ts) | Sliding Window |
37-
| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | Medium | [ts](./TypeScript/3.longest-substring-without-repeating-characters.ts) | Sliding Window |
38-
| 424 | [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/) | Medium | [ts](./TypeScript/424.longest-repeating-character-replacement.ts) | Sliding Window |
39-
| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) | Easy | [ts](./TypeScript/206.reverse-linked-list.ts) [rkt](./Racket/206.reverse-linked-list.rkt) | Linked List |
40-
| 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | Easy | [ts](./TypeScript/21.merge-two-sorted-lists.ts) | Linked List |
7+
| # | Title | Difficulty | Solution | Category |
8+
| --- | ------------------------------------------------------------------------------------------------------------------------------- | ---------- | --------------------------------------------------------------------------------------------- | ---------------- |
9+
| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) | Easy | [ts](./TypeScript/217.contains-duplicate.ts) | Arrays & Hashing |
10+
| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/) | Easy | [ts](./TypeScript/242.valid-anagram.ts) | Arrays & Hashing |
11+
| 242 | [Two Sum](https://leetcode.com/problems/two-sum/) | Easy | [ts](./TypeScript/1.two-sum.ts) | Arrays & Hashing |
12+
| 49 | [Group Anagrams](https://leetcode.com/problems/two-sum/) | Medium | [ts](./TypeScript/49.group-anagrams.ts) | Arrays & Hashing |
13+
| 347 | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/) | Medium | [ts](./TypeScript/347.top-k-frequent-elements.ts) | Arrays & Hashing |
14+
| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | Medium | [ts](./TypeScript/238.product-of-array-except-self.ts) | Arrays & Hashing |
15+
| 36 | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | Medium | [ts](./TypeScript/36.valid-sudoku.ts) | Arrays & Hashing |
16+
| 659 | [Encode and Decode Strings](https://www.lintcode.com/problem/659/) | Medium | [ts](./TypeScript/659.encode-and-decode-strings.ts) | Arrays & Hashing |
17+
| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/) | Medium | [ts](./TypeScript/128.longest-consecutive-sequence.ts) | Arrays & Hashing |
18+
| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) | Easy | [ts](./TypeScript/125.valid-palindrome.ts) | Two Pointers |
19+
| 167 | [Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | Medium | [ts](./TypeScript/167.two-sum-ii-input-array-is-sorted.ts) | Two Pointers |
20+
| 15 | [3Sum](https://leetcode.com/problems/3sum/) | Medium | [ts](./TypeScript/15.3sum.ts) | Two Pointers |
21+
| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) | Medium | [ts](./TypeScript/11.container-with-most-water.ts) | Two Pointers |
22+
| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) | Hard | [ts](./TypeScript/42.trapping-rain-water.ts) | Two Pointers |
23+
| 20 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | Easy | [ts](./TypeScript/20.valid-parentheses.ts) | Stack |
24+
| 155 | [Min Stack](https://leetcode.com/problems/min-stack/) | Medium | [ts](./TypeScript/155.min-stack.ts) | Stack |
25+
| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | Medium | [ts](./TypeScript/150.evaluate-reverse-polish-notation.ts) | Stack |
26+
| 22 | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/) | Medium | [ts](./TypeScript/22.generate-parentheses.ts) | Stack |
27+
| 739 | [Daily Temperatures](https://leetcode.com/problems/daily-temperatures/) | Medium | [ts](./TypeScript/739.daily-temperatures.ts) | Stack |
28+
| 853 | [Car Fleet](https://leetcode.com/problems/car-fleet/) | Medium | [ts](./TypeScript/853.car-fleet.ts) | Stack |
29+
| 84 | [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) | Hard | [ts](./TypeScript/84.largest-rectangle-in-histogram.ts) | Stack |
30+
| 704 | [Binary Search](https://leetcode.com/problems/binary-search/) | Easy | [ts](./TypeScript/704.binary-search.ts) | Binary Search |
31+
| 74 | [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) | Medium | [ts](./TypeScript/74.search-a-2d-matrix.ts) | Binary Search |
32+
| 875 | [Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/) | Medium | [ts](./TypeScript/875.koko-eating-bananas.ts) | Binary Search |
33+
| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | [ts](./TypeScript/153.find-minimum-in-rotated-sorted-array.ts) | Binary Search |
34+
| 33 | [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) | Medium | [ts](./TypeScript/33.search-in-rotated-sorted-array.ts) | Binary Search |
35+
| 981 | [Time Based Key-Value Store](https://leetcode.com/problems/time-based-key-value-store/) | Medium | [ts](./TypeScript/981.time-based-key-value-store.ts) | Binary Search |
36+
| 121 | [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | Easy | [ts](./TypeScript/121.best-time-to-buy-and-sell-stock.ts) | Sliding Window |
37+
| 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | Medium | [ts](./TypeScript/3.longest-substring-without-repeating-characters.ts) | Sliding Window |
38+
| 424 | [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/) | Medium | [ts](./TypeScript/424.longest-repeating-character-replacement.ts) | Sliding Window |
39+
| 206 | [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) | Easy | [ts](./TypeScript/206.reverse-linked-list.ts) [rkt](./Racket/206.reverse-linked-list.rkt) | Linked List |
40+
| 21 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | Easy | [ts](./TypeScript/21.merge-two-sorted-lists.ts) [rkt](./Racket/21.merge-two-sorted-lists.rkt) | Linked List |
4141

4242
### Others
4343

Racket/21.merge-two-sorted-lists.rkt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#lang racket
2+
3+
(struct list-node
4+
(val next) #:mutable #:transparent)
5+
6+
(define (make-list-node [val 0])
7+
(list-node val #f))
8+
9+
10+
(define/contract (merge-two-lists list1 list2)
11+
(-> (or/c list-node? #f) (or/c list-node? #f) (or/c list-node? #f))
12+
(cond ((false? list1) list2)
13+
((false? list2) list1)
14+
((< (list-node-val list1) (list-node-val list2)) (list-node (list-node-val list1) (merge-two-lists (list-node-next list1) list2)))
15+
(else (list-node (list-node-val list2) (merge-two-lists list1 (list-node-next list2))))))

0 commit comments

Comments
 (0)