leetcode

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

commit 55f47e6e64aaae6e8776d3d57dddce82d6c05586
parent 75204a6fc4bacaceadaa5a523db6ef8162e5b77d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 13 Mar 2024 18:23:37 +0000

Daily Problem

Diffstat:
AProblems/2485.cpp | 22++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/Problems/2485.cpp b/Problems/2485.cpp @@ -0,0 +1,22 @@ +class Solution { + public: + int pivotInteger(const int n) const { + int i = 1, j = n, l = 0, h = 0; + while (i < j) { + if (l < h) + l += i++; + else + h += j--; + } + return l == h ? i : -1; + } +}; + +class Solution { + public: + int pivotInteger(const int n) const { + const int sum = n * (n + 1) / 2; + const int pivot = sqrt(sum); + return pivot * pivot == sum ? pivot : -1; + } +}; diff --git a/README.md b/README.md @@ -1083,6 +1083,7 @@ for solving problems. | 2477 | Medium | [Minimum Fuel Cost to Report to the Capital](Problems/2477.cpp) | | 2482 | Medium | [Difference Between Ones and Zeros in Row and Column](Problems/2482.cpp) | | 2483 | Medium | [Minimum Penalty for a Shop](Problems/2483.cpp) | +| 2485 | Easy | [Find the Pivot Integer](Problems/2485.cpp) | | 2486 | Medium | [Append Characters to String to Make Subsequence](Problems/2486.cpp) | | 2487 | Medium | [Remove Nodes From Linked List](Problems/2487.cpp) | | 2491 | Medium | [Divide Players Into Teams of Equal Skill](Problems/2491.cpp) |