leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit b994c8b4e336316ae6ab33bee7dcb2c0d9852b84
parent 1cd4ccce3e5f30b0c175c48e7ecd7779b3df2226
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon, 24 Apr 2023 11:03:48 +0200

Random Problem

Diffstat:
AProblems/0086.cpp | 18++++++++++++++++++
MREADME.md | 3++-
2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Problems/0086.cpp b/Problems/0086.cpp @@ -0,0 +1,18 @@ +class Solution { +public: + ListNode *partition(ListNode *head, int x) { + ListNode hless, hmore; + ListNode *less = &hless, *more = &hmore; + + for (ListNode *crnt = head; crnt; crnt = crnt->next) { + if (crnt->val < x) + less = less->next = crnt; + else + more = more->next = crnt; + } + + less->next = hmore.next; + more->next = nullptr; + return hless.next; + } +}; diff --git a/README.md b/README.md @@ -101,6 +101,7 @@ for solving problems. | 0082 | Medium | [Remove Duplicates from Sorted List II](Problems/0082.cpp) | | 0083 | Easy | [Remove Duplicates from Sorted List](Problems/0083.cpp) | | 0084 | Hard | [Largest Rectangle in Histogram](Problems/0084.cpp) | +| 0086 | Medium | [Partition List](Problems/0086.cpp) | | 0087 | Hard | [Scramble String](Problems/0087.cpp) | | 0088 | Easy | [Merge Sorted Array](Problems/0088.cpp) | | 0090 | Medium | [Subsets II](Problems/0090.cpp) | @@ -431,6 +432,7 @@ for solving problems. | 1379 | Easy | [Find a Corresponding Node of a Binary Tree in a Clone of That Tree](Problems/1379.cpp) | | 1382 | Medium | [Balance a Binary Search Tree](Problems/1382.cpp) | | 1402 | Hard | [Reducing Dishes](Problems/1402.cpp) | +| 1416 | Hard | [Restore The Array](Problems/1416.cpp) | | 1425 | Hard | [Constrained Subsequence Sum](Problems/1425.cpp) | | 1431 | Easy | [Kids With the Greatest Number of Candies](Problems/1431.cpp) | | 1436 | Easy | [Destination City](Problems/1436.cpp) | @@ -520,5 +522,4 @@ for solving problems. | 2477 | Medium | [Minimum Fuel Cost to Report to the Capital](Problems/2477.cpp) | | 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) | | 2497 | Medium | [Maximum Star Sum of a Graph](Problems/2497.cpp) | -| 1416 | Hard | [Restore The Array](Problems/1416.cpp) |