Skip to content

Commit 44f61f5

Browse files
authored
feat: add solutions to lc problems: No.2815~2818 (doocs#1440)
* No.2815.Max Pair Sum in an Array * No.2816.Double a Number Represented as a Linked List * No.2817.Minimum Absolute Difference Between Elements With Constraint * No.2818.Apply Operations to Maximize Score
1 parent 49ed9fb commit 44f61f5

File tree

13 files changed

+2638
-19
lines changed

13 files changed

+2638
-19
lines changed

Diff for: solution/2800-2899/2815.Max Pair Sum in an Array/README_EN.md

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ It can be shown that there are no other pairs with equal maximum digits, so the
3737

3838
## Solutions
3939

40+
**Solution 1: Enumeration**
41+
42+
First, we initialize the answer variable $ans=-1$. Next, we directly enumerate all pairs $(nums[i], nums[j])$ where $i \lt j$, and calculate their sum $v=nums[i] + nums[j]$. If $v$ is greater than $ans$ and the largest digit of $nums[i]$ and $nums[j]$ are the same, then we update $ans$ with $v$.
43+
44+
The time complexity is $O(n^2 \times \log M)$, where $n$ is the length of the array and $M$ is the maximum value in the array.
45+
4046
<!-- tabs:start -->
4147

4248
### **Python3**

Diff for: solution/2800-2899/2816.Double a Number Represented as a Linked List/README_EN.md

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636

3737
## Solutions
3838

39+
**Solution 1: Reverse Linked List + Simulation**
40+
41+
First, we reverse the linked list, then simulate the multiplication operation, and finally reverse the linked list back.
42+
43+
Time complexity is $O(n)$, where $n$ is the length of the linked list. Ignoring the space taken by the answer linked list, the space complexity is $O(1)$.
44+
3945
<!-- tabs:start -->
4046

4147
### **Python3**

0 commit comments

Comments
 (0)