Skip to content

Commit 87cd500

Browse files
author
Partho Biswas
committed
1265. Print Immutable Linked List in Reverse
1 parent f12940c commit 87cd500

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ I have solved quite a number of problems from several topics. See the below tabl
292292
|27| **[203. Remove Linked List Elements](https://tinyurl.com/y6bmycyr)** | [Python](https://tinyurl.com/wu6rdaw/203_Remove_Linked_List_Elements.py), [Swift](https://tinyurl.com/wuja3c4/203_Remove_Linked_List_Elements.swift) | --- | Easy | |
293293
|28| **[432. All O`one Data Structure](https://tinyurl.com/zqkzen4)** | [Python](https://tinyurl.com/wu6rdaw/432_All_O_one_Data_Structure.py), [Swift](https://tinyurl.com/wuja3c4/432_All_O_one_Data_Structure.swift) | [Art 1](https://tinyurl.com/y2ame7dc) | Hard | Super hard and super important |
294294
|29| **[426. Convert Binary Search Tree to Sorted Doubly Linked List](https://tinyurl.com/y5urjasp)** | [Python](https://tinyurl.com/wu6rdaw/426_Convert_Binary_Search_Tree_to_Sorted_Doubly_Linked_List.py), [Swift](https://tinyurl.com/wuja3c4/426_Convert_Binary_Search_Tree_to_Sorted_Doubly_Linked_List.swift) | [Art 1](https://tinyurl.com/yyq67lc7) | Medium | Super important |
295+
|30| **[1265. Print Immutable Linked List in Reverse](https://tinyurl.com/y5ksjt65)** | [Python](https://tinyurl.com/wu6rdaw/1265_Print_Immutable_Linked_List_in_Reverse.py), [Swift](https://tinyurl.com/wuja3c4/1265_Print_Immutable_Linked_List_in_Reverse.swift) | [Art 1](https://tinyurl.com/yxtb5wv4) | Medium | Really?? Are we supposed to solve a puzzle in an interview? |
295296

296297

297298
</p>
@@ -1432,4 +1433,4 @@ Learn the following modules by heart. Just knowing all of the following items wi
14321433
[license-url]: https://github.com/partho-maple/coding-interview-gym/LICENSE.txt
14331434
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg??style=flat&logo=linkedin&colorB=555
14341435
[linkedin-url]: https://www.linkedin.com/in/partho-maple/
1435-
[product-screenshot]: images/screenshot.png
1436+
[product-screenshot]: images/screenshot.png
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Definition for ImmutableListNode.
3+
* public class ImmutableListNode {
4+
* public func printValue() {}
5+
* public func getNext() -> ImmutableListNode? {}
6+
* }
7+
*/
8+
9+
// Approach 1: Time O(n) , Space O(n)
10+
class Solution {
11+
func printLinkedListInReverse(_ head: ImmutableListNode?) {
12+
guard let head = head else {
13+
return
14+
}
15+
printLinkedListInReverse(head.getNext())
16+
head.printValue()
17+
}
18+
}

0 commit comments

Comments
 (0)