You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: lcci/02.05.Sum Lists/README_EN.md
+18-10
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,15 @@
32
32
33
33
## Solutions
34
34
35
-
### Solution 1
35
+
### Solution 1: Simulation
36
+
37
+
We traverse two linked lists $l_1$ and $l_2$ simultaneously, and use a variable $carry$ to indicate whether there is a carry-over currently.
38
+
39
+
During each traversal, we take out the current digit of the corresponding linked list, calculate the sum of them and the carry-over $carry$, then update the value of the carry-over, and finally add the value of the current digit to the answer linked list. The traversal ends when both linked lists have been traversed and the carry-over is $0$.
40
+
41
+
Finally, we return the head node of the answer linked list.
42
+
43
+
The time complexity is $O(\max(m, n))$, where $m$ and $n$ are the lengths of the two linked lists respectively. We need to traverse all positions of the two linked lists, and it only takes $O(1)$ time to process each position. Ignoring the space consumption of the answer, the space complexity is $O(1)$.
| 3001 | [Minimum Moves to Capture The Queen](/solution/3000-3099/3001.Minimum%20Moves%20to%20Capture%20The%20Queen/README_EN.md) | `Array`,`Enumeration` | Medium | Weekly Contest 379 |
3013
3013
| 3002 | [Maximum Size of a Set After Removals](/solution/3000-3099/3002.Maximum%20Size%20of%20a%20Set%20After%20Removals/README_EN.md) | `Greedy`,`Array`,`Hash Table` | Medium | Weekly Contest 379 |
3014
3014
| 3003 | [Maximize the Number of Partitions After Operations](/solution/3000-3099/3003.Maximize%20the%20Number%20of%20Partitions%20After%20Operations/README_EN.md) | `Bit Manipulation`,`String`,`Dynamic Programming`,`Bitmask` | Hard | Weekly Contest 379 |
3015
-
| 3004 | [Maximum Subtree of the Same Color](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README_EN.md) | `Tree`,`Depth-First Search`,`Array` | Medium | 🔒 |
3015
+
| 3004 | [Maximum Subtree of the Same Color](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README_EN.md) | `Tree`,`Depth-First Search`,`Array`,`Dynamic Programming` | Medium | 🔒 |
3016
3016
| 3005 | [Count Elements With Maximum Frequency](/solution/3000-3099/3005.Count%20Elements%20With%20Maximum%20Frequency/README_EN.md) | `Array`,`Hash Table`,`Counting` | Easy | Weekly Contest 380 |
3017
3017
| 3006 | [Find Beautiful Indices in the Given Array I](/solution/3000-3099/3006.Find%20Beautiful%20Indices%20in%20the%20Given%20Array%20I/README_EN.md) | `Two Pointers`,`String`,`Binary Search`,`String Matching`,`Hash Function`,`Rolling Hash` | Medium | Weekly Contest 380 |
3018
3018
| 3007 | [Maximum Number That Sum of the Prices Is Less Than or Equal to K](/solution/3000-3099/3007.Maximum%20Number%20That%20Sum%20of%20the%20Prices%20Is%20Less%20Than%20or%20Equal%20to%20K/README_EN.md) | `Bit Manipulation`,`Binary Search`,`Dynamic Programming` | Medium | Weekly Contest 380 |
| 3020 | [Find the Maximum Number of Elements in Subset](/solution/3000-3099/3020.Find%20the%20Maximum%20Number%20of%20Elements%20in%20Subset/README_EN.md) | `Array`,`Hash Table`,`Enumeration` | Medium | Weekly Contest 382 |
3032
3032
| 3021 | [Alice and Bob Playing Flower Game](/solution/3000-3099/3021.Alice%20and%20Bob%20Playing%20Flower%20Game/README_EN.md) | `Math` | Medium | Weekly Contest 382 |
3033
3033
| 3022 | [Minimize OR of Remaining Elements Using Operations](/solution/3000-3099/3022.Minimize%20OR%20of%20Remaining%20Elements%20Using%20Operations/README_EN.md) | `Greedy`,`Bit Manipulation`,`Array` | Hard | Weekly Contest 382 |
3034
-
| 3023 | [Find Pattern in Infinite Stream I](/solution/3000-3099/3023.Find%20Pattern%20in%20Infinite%20Stream%20I/README_EN.md) | | Medium | 🔒 |
| 3025 | [Find the Number of Ways to Place People I](/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/README_EN.md) | | Medium | Biweekly Contest 123 |
3037
-
| 3026 | [Maximum Good Subarray Sum](/solution/3000-3099/3026.Maximum%20Good%20Subarray%20Sum/README_EN.md) | | Medium | Biweekly Contest 123 |
3038
-
| 3027 | [Find the Number of Ways to Place People II](/solution/3000-3099/3027.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20II/README_EN.md) | | Hard | Biweekly Contest 123 |
3039
-
| 3028 | [Ant on the Boundary](/solution/3000-3099/3028.Ant%20on%20the%20Boundary/README_EN.md) | | Easy | Weekly Contest 383 |
3040
-
| 3029 | [Minimum Time to Revert Word to Initial State I](/solution/3000-3099/3029.Minimum%20Time%20to%20Revert%20Word%20to%20Initial%20State%20I/README_EN.md) | | Medium | Weekly Contest 383 |
3041
-
| 3030 | [Find the Grid of Region Average](/solution/3000-3099/3030.Find%20the%20Grid%20of%20Region%20Average/README_EN.md) | | Medium | Weekly Contest 383 |
3042
-
| 3031 | [Minimum Time to Revert Word to Initial State II](/solution/3000-3099/3031.Minimum%20Time%20to%20Revert%20Word%20to%20Initial%20State%20II/README_EN.md) | | Hard | Weekly Contest 383 |
3034
+
| 3023 | [Find Pattern in Infinite Stream I](/solution/3000-3099/3023.Find%20Pattern%20in%20Infinite%20Stream%20I/README_EN.md) | `Array`,`String`,`String Matching`,`Sliding Window` | Medium | 🔒 |
| 3025 | [Find the Number of Ways to Place People I](/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/README_EN.md) | `Geometry`,`Array`,`Math`,`Enumeration`,`Sorting` | Medium | Biweekly Contest 123 |
3037
+
| 3026 | [Maximum Good Subarray Sum](/solution/3000-3099/3026.Maximum%20Good%20Subarray%20Sum/README_EN.md) | `Array`,`Hash Table`,`Prefix Sum` | Medium | Biweekly Contest 123 |
3038
+
| 3027 | [Find the Number of Ways to Place People II](/solution/3000-3099/3027.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20II/README_EN.md) | `Geometry`,`Array`,`Math`,`Enumeration`,`Sorting` | Hard | Biweekly Contest 123 |
3039
+
| 3028 | [Ant on the Boundary](/solution/3000-3099/3028.Ant%20on%20the%20Boundary/README_EN.md) | `Array`,`Prefix Sum`,`Simulation` | Easy | Weekly Contest 383 |
3040
+
| 3029 | [Minimum Time to Revert Word to Initial State I](/solution/3000-3099/3029.Minimum%20Time%20to%20Revert%20Word%20to%20Initial%20State%20I/README_EN.md) | `String`,`String Matching`,`Hash Function`,`Rolling Hash` | Medium | Weekly Contest 383 |
3041
+
| 3030 | [Find the Grid of Region Average](/solution/3000-3099/3030.Find%20the%20Grid%20of%20Region%20Average/README_EN.md) | `Array`,`Matrix` | Medium | Weekly Contest 383 |
3042
+
| 3031 | [Minimum Time to Revert Word to Initial State II](/solution/3000-3099/3031.Minimum%20Time%20to%20Revert%20Word%20to%20Initial%20State%20II/README_EN.md) | `String`,`String Matching`,`Hash Function`,`Rolling Hash` | Hard | Weekly Contest 383 |
0 commit comments