Skip to content

feat: add solutions to lc problems: No.2815~2818 #1440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions solution/2800-2899/2815.Max Pair Sum in an Array/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ It can be shown that there are no other pairs with equal maximum digits, so the

## Solutions

**Solution 1: Enumeration**

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$.

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.

<!-- tabs:start -->

### **Python3**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@

## Solutions

**Solution 1: Reverse Linked List + Simulation**

First, we reverse the linked list, then simulate the multiplication operation, and finally reverse the linked list back.

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)$.

<!-- tabs:start -->

### **Python3**
Expand Down
Loading