Skip to content

Commit 5622877

Browse files
authored
Added tasks 138-160
1 parent 39fcf21 commit 5622877

File tree

11 files changed

+995
-0
lines changed

11 files changed

+995
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
8484
|-|-|-|-|-|-
85+
| 0153 |[Find Minimum in Rotated Sorted Array](src/main/php/g0101_0200/s0153_find_minimum_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 9 | 73.47
8586

8687
### Binary Search II
8788

@@ -220,6 +221,7 @@
220221

221222
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
222223
|-|-|-|-|-|-
224+
| 0152 |[Maximum Product Subarray](src/main/php/g0101_0200/s0152_maximum_product_subarray)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 15 | 92.86
223225

224226
#### Day 7
225227

@@ -236,6 +238,7 @@
236238

237239
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
238240
|-|-|-|-|-|-
241+
| 0139 |[Word Break](src/main/php/g0101_0200/s0139_word_break)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 7 | 75.00
239242
| 0042 |[Trapping Rain Water](src/main/php/g0001_0100/s0042_trapping_rain_water)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 29 | 69.15
240243

241244
#### Day 10
@@ -439,6 +442,7 @@
439442

440443
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
441444
|-|-|-|-|-|-
445+
| 0138 |[Copy List with Random Pointer](src/main/php/g0101_0200/s0138_copy_list_with_random_pointer)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 2300 | 60.00
442446

443447
#### Day 15
444448

@@ -460,6 +464,7 @@
460464

461465
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
462466
|-|-|-|-|-|-
467+
| 0155 |[Min Stack](src/main/php/g0101_0200/s0155_min_stack)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 19 | 100.00
463468

464469
#### Day 19
465470

@@ -617,6 +622,7 @@
617622

618623
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
619624
|-|-|-|-|-|-
625+
| 0142 |[Linked List Cycle II](src/main/php/g0101_0200/s0142_linked_list_cycle_ii)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 7 | 100.00
620626

621627
#### Day 5 Greedy
622628

@@ -701,6 +707,7 @@
701707

702708
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
703709
|-|-|-|-|-|-
710+
| 0148 |[Sort List](src/main/php/g0101_0200/s0148_sort_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 63 | 97.30
704711

705712
#### Day 5 Greedy
706713

@@ -748,6 +755,7 @@
748755

749756
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
750757
|-|-|-|-|-|-
758+
| 0152 |[Maximum Product Subarray](src/main/php/g0101_0200/s0152_maximum_product_subarray)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 15 | 92.86
751759

752760
#### Day 14 Sliding Window/Two Pointer
753761

@@ -766,6 +774,7 @@
766774

767775
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
768776
|-|-|-|-|-|-
777+
| 0155 |[Min Stack](src/main/php/g0101_0200/s0155_min_stack)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 19 | 100.00
769778

770779
#### Day 17 Interval
771780

@@ -814,6 +823,7 @@
814823
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
815824
|-|-|-|-|-|-
816825
| 0033 |[Search in Rotated Sorted Array](src/main/php/g0001_0100/s0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 7 | 83.17
826+
| 0153 |[Find Minimum in Rotated Sorted Array](src/main/php/g0101_0200/s0153_find_minimum_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 9 | 73.47
817827

818828
#### Udemy Arrays
819829

@@ -858,8 +868,13 @@
858868
|-|-|-|-|-|-
859869
| 0114 |[Flatten Binary Tree to Linked List](src/main/php/g0101_0200/s0114_flatten_binary_tree_to_linked_list)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Linked_List, Big_O_Time_O(N)_Space_O(N) | 3 | 100.00
860870
| 0024 |[Swap Nodes in Pairs](src/main/php/g0001_0100/s0024_swap_nodes_in_pairs)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 3 | 85.71
871+
| 0142 |[Linked List Cycle II](src/main/php/g0101_0200/s0142_linked_list_cycle_ii)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 7 | 100.00
872+
| 0141 |[Linked List Cycle](src/main/php/g0101_0200/s0141_linked_list_cycle)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 8 | 90.60
861873
| 0021 |[Merge Two Sorted Lists](src/main/php/g0001_0100/s0021_merge_two_sorted_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 3 | 90.57
874+
| 0160 |[Intersection of Two Linked Lists](src/main/php/g0101_0200/s0160_intersection_of_two_linked_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 30 | 81.67
875+
| 0138 |[Copy List with Random Pointer](src/main/php/g0101_0200/s0138_copy_list_with_random_pointer)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 2300 | 60.00
862876
| 0025 |[Reverse Nodes in k-Group](src/main/php/g0001_0100/s0025_reverse_nodes_in_k_group)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 3 | 100.00
877+
| 0146 |[LRU Cache](src/main/php/g0101_0200/s0146_lru_cache)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 402 | 41.18
863878

864879
#### Udemy Tree Stack Queue
865880

@@ -885,6 +900,8 @@
885900

886901
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
887902
|-|-|-|-|-|-
903+
| 0139 |[Word Break](src/main/php/g0101_0200/s0139_word_break)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 7 | 75.00
904+
| 0152 |[Maximum Product Subarray](src/main/php/g0101_0200/s0152_maximum_product_subarray)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 15 | 92.86
888905
| 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 3 | 82.81
889906
| 0064 |[Minimum Path Sum](src/main/php/g0001_0100/s0064_minimum_path_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 20 | 81.48
890907
| 0072 |[Edit Distance](src/main/php/g0001_0100/s0072_edit_distance)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 29 | 75.00
@@ -909,6 +926,7 @@
909926

910927
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
911928
|-|-|-|-|-|-
929+
| 0155 |[Min Stack](src/main/php/g0101_0200/s0155_min_stack)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 19 | 100.00
912930

913931
### Data Structure I
914932

@@ -950,6 +968,7 @@
950968

951969
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
952970
|-|-|-|-|-|-
971+
| 0141 |[Linked List Cycle](src/main/php/g0101_0200/s0141_linked_list_cycle)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 8 | 90.60
953972
| 0021 |[Merge Two Sorted Lists](src/main/php/g0001_0100/s0021_merge_two_sorted_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 3 | 90.57
954973

955974
#### Day 8 Linked List
@@ -1052,11 +1071,13 @@
10521071
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10531072
|-|-|-|-|-|-
10541073
| 0002 |[Add Two Numbers](src/main/php/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)) | 13 | 73.83
1074+
| 0142 |[Linked List Cycle II](src/main/php/g0101_0200/s0142_linked_list_cycle_ii)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(N)_Space_O(1) | 7 | 100.00
10551075

10561076
#### Day 11 Linked List
10571077

10581078
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10591079
|-|-|-|-|-|-
1080+
| 0160 |[Intersection of Two Linked Lists](src/main/php/g0101_0200/s0160_intersection_of_two_linked_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 30 | 81.67
10601081

10611082
#### Day 12 Linked List
10621083

@@ -1074,6 +1095,7 @@
10741095

10751096
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10761097
|-|-|-|-|-|-
1098+
| 0155 |[Min Stack](src/main/php/g0101_0200/s0155_min_stack)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 19 | 100.00
10771099

10781100
#### Day 15 Tree
10791101

@@ -1204,6 +1226,7 @@
12041226

12051227
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12061228
|-|-|-|-|-|-
1229+
| 0153 |[Find Minimum in Rotated Sorted Array](src/main/php/g0101_0200/s0153_find_minimum_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 9 | 73.47
12071230

12081231
#### Day 3 Two Pointers
12091232

@@ -1280,6 +1303,7 @@
12801303

12811304
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12821305
|-|-|-|-|-|-
1306+
| 0139 |[Word Break](src/main/php/g0101_0200/s0139_word_break)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 7 | 75.00
12831307

12841308
#### Day 16 Dynamic Programming
12851309

@@ -1316,6 +1340,16 @@
13161340

13171341
| # | Title | Difficulty | Tag | Time, ms | Time, %
13181342
|------|----------------|-------------|-------------|----------|--------
1343+
| 0160 |[Intersection of Two Linked Lists](src/main/php/g0101_0200/s0160_intersection_of_two_linked_lists)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Udemy_Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 30 | 81.67
1344+
| 0155 |[Min Stack](src/main/php/g0101_0200/s0155_min_stack)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Data_Structure_II_Day_14_Stack_Queue, Programming_Skills_II_Day_18, Level_2_Day_16_Design, Udemy_Design, Big_O_Time_O(1)_Space_O(N) | 19 | 100.00
1345+
| 0153 |[Find Minimum in Rotated Sorted Array](src/main/php/g0101_0200/s0153_find_minimum_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_II_Day_2_Binary_Search, Binary_Search_I_Day_12, Udemy_Binary_Search, Big_O_Time_O(log_N)_Space_O(log_N) | 9 | 73.47
1346+
| 0152 |[Maximum Product Subarray](src/main/php/g0101_0200/s0152_maximum_product_subarray)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Dynamic_Programming_I_Day_6, Level_2_Day_13_Dynamic_Programming, Udemy_Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 15 | 92.86
1347+
| 0148 |[Sort List](src/main/php/g0101_0200/s0148_sort_list)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Level_2_Day_4_Linked_List, Big_O_Time_O(log(N))_Space_O(log(N)) | 63 | 97.30
1348+
| 0146 |[LRU Cache](src/main/php/g0101_0200/s0146_lru_cache)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Udemy_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 402 | 41.18
1349+
| 0142 |[Linked List Cycle II](src/main/php/g0101_0200/s0142_linked_list_cycle_ii)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_10_Linked_List, Level_1_Day_4_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 7 | 100.00
1350+
| 0141 |[Linked List Cycle](src/main/php/g0101_0200/s0141_linked_list_cycle)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_I_Day_7_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 8 | 90.60
1351+
| 0139 |[Word Break](src/main/php/g0101_0200/s0139_word_break)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Dynamic_Programming, Trie, Memoization, Algorithm_II_Day_15_Dynamic_Programming, Dynamic_Programming_I_Day_9, Udemy_Dynamic_Programming, Big_O_Time_O(M+max\*N)_Space_O(M+N+max) | 7 | 75.00
1352+
| 0138 |[Copy List with Random Pointer](src/main/php/g0101_0200/s0138_copy_list_with_random_pointer)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Programming_Skills_II_Day_14, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(N) | 2300 | 60.00
13191353
| 0136 |[Single Number](src/main/php/g0101_0200/s0136_single_number)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Data_Structure_II_Day_1_Array, Algorithm_I_Day_14_Bit_Manipulation, Udemy_Integers, Big_O_Time_O(N)_Space_O(1) | 33 | 80.08
13201354
| 0131 |[Palindrome Partitioning](src/main/php/g0101_0200/s0131_palindrome_partitioning)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(N\*2^N)_Space_O(2^N\*N) | 159 | 61.90
13211355
| 0128 |[Longest Consecutive Sequence](src/main/php/g0101_0200/s0128_longest_consecutive_sequence)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Big_O_Time_O(N_log_N)_Space_O(1) | 154 | 75.61
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-Php/LeetCode-in-Php?label=Stars&style=flat-square)](https://github.com/LeetCode-in-Php/LeetCode-in-Php)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-Php/LeetCode-in-Php?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-Php/LeetCode-in-Php/fork)
3+
4+
## 138\. Copy List with Random Pointer
5+
6+
Medium
7+
8+
A linked list of length `n` is given such that each node contains an additional random pointer, which could point to any node in the list, or `null`.
9+
10+
Construct a [**deep copy**](https://en.wikipedia.org/wiki/Object_copying#Deep_copy) of the list. The deep copy should consist of exactly `n` **brand new** nodes, where each new node has its value set to the value of its corresponding original node. Both the `next` and `random` pointer of the new nodes should point to new nodes in the copied list such that the pointers in the original list and copied list represent the same list state. **None of the pointers in the new list should point to nodes in the original list**.
11+
12+
For example, if there are two nodes `X` and `Y` in the original list, where `X.random --> Y`, then for the corresponding two nodes `x` and `y` in the copied list, `x.random --> y`.
13+
14+
Return _the head of the copied linked list_.
15+
16+
The linked list is represented in the input/output as a list of `n` nodes. Each node is represented as a pair of `[val, random_index]` where:
17+
18+
* `val`: an integer representing `Node.val`
19+
* `random_index`: the index of the node (range from `0` to `n-1`) that the `random` pointer points to, or `null` if it does not point to any node.
20+
21+
Your code will **only** be given the `head` of the original linked list.
22+
23+
**Example 1:**
24+
25+
![](https://assets.leetcode.com/uploads/2019/12/18/e1.png)
26+
27+
**Input:** head = \[\[7,null],[13,0],[11,4],[10,2],[1,0]]
28+
29+
**Output:** [[7,null],[13,0],[11,4],[10,2],[1,0]]
30+
31+
**Example 2:**
32+
33+
![](https://assets.leetcode.com/uploads/2019/12/18/e2.png)
34+
35+
**Input:** head = \[\[1,1],[2,1]]
36+
37+
**Output:** [[1,1],[2,1]]
38+
39+
**Example 3:**
40+
41+
**![](https://assets.leetcode.com/uploads/2019/12/18/e3.png)**
42+
43+
**Input:** head = \[\[3,null],[3,0],[3,null]]
44+
45+
**Output:** [[3,null],[3,0],[3,null]]
46+
47+
**Example 4:**
48+
49+
**Input:** head = []
50+
51+
**Output:** []
52+
53+
**Explanation:** The given linked list is empty (null pointer), so return null.
54+
55+
**Constraints:**
56+
57+
* `0 <= n <= 1000`
58+
* `-10000 <= Node.val <= 10000`
59+
* `Node.random` is `null` or is pointing to some node in the linked list.
60+
61+
## Solution
62+
63+
```php
64+
use leetcode\com_github_leetcode\random\Node;
65+
66+
/**
67+
* Definition for a Node.
68+
* class Node {
69+
* public $val = null;
70+
* public $next = null;
71+
* public $random = null;
72+
* function __construct($val = 0) {
73+
* $this->val = $val;
74+
* $this->next = null;
75+
* $this->random = null;
76+
* }
77+
* }
78+
*/
79+
class Solution {
80+
/**
81+
* @param Node $head
82+
* @return Node
83+
*/
84+
public function copyRandomList($head) {
85+
if ($head == null) {
86+
return null;
87+
}
88+
$curr = $head;
89+
while ($curr != null) {
90+
$clonedNode = new Node($curr->val);
91+
$clonedNode->next = $curr->next;
92+
$curr->next = $clonedNode;
93+
$curr = $clonedNode->next;
94+
}
95+
$curr = $head;
96+
while ($curr != null) {
97+
if ($curr->random != null) {
98+
$curr->next->random = $curr->random->next;
99+
} else {
100+
$curr->next->random = null;
101+
}
102+
$curr = $curr->next->next;
103+
}
104+
$curr = $head;
105+
$newHead = null;
106+
while ($curr != null) {
107+
if ($newHead == null) {
108+
$clonedNode = $curr->next;
109+
$newHead = $clonedNode;
110+
} else {
111+
$clonedNode = $curr->next;
112+
}
113+
$curr->next = $clonedNode->next;
114+
if ($curr->next != null) {
115+
$clonedNode->next = $curr->next->next;
116+
} else {
117+
$clonedNode->next = null;
118+
}
119+
$curr = $curr->next;
120+
}
121+
return $newHead;
122+
}
123+
}
124+
```

0 commit comments

Comments
 (0)