leetcode

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

commit cd065198e0c2a24ee88af2921943a1d7b926167b
parent 7782c6d85a1b856959563108e1f5fef1851697a9
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue, 12 Dec 2023 23:10:42 +0000

Daily Problem

Diffstat:
AProblems/1464.cpp | 16++++++++++++++++
MREADME.md | 1+
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/Problems/1464.cpp b/Problems/1464.cpp @@ -0,0 +1,16 @@ +class Solution { + public: + int maxProduct(const vector<int> &nums) const { + int a = max(nums[0], nums[1]); + int b = min(nums[0], nums[1]); + for (int i = 2; i < nums.size(); i++) { + if (nums[i] > a) { + b = a; + a = nums[i]; + } else { + b = max(b, nums[i]); + } + } + return (a - 1) * (b - 1); + } +}; diff --git a/README.md b/README.md @@ -684,6 +684,7 @@ for solving problems. | 1457 | Medium | [Pseudo-Palindromic Paths in a Binary Tree](Problems/1457.cpp) | | 1458 | Hard | [Max Dot Product of Two Subsequences](Problems/1458.cpp) | | 1462 | Medium | [Course Schedule IV](Problems/1462.cpp) | +| 1464 | Easy | [Maximum Product of Two Elements in an Array](Problems/1464.cpp) | | 1466 | Medium | [Reorder Routes to Make All Paths Lead to the City Zero](Problems/1466.cpp) | | 1470 | Easy | [Shuffle the Array](Problems/1470.cpp) | | 1471 | Medium | [The k Strongest Values in an Array](Problems/1471.cpp) |