leetcode

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

commit 7b10c7d04d0752b1776c6f58958966d9a2aaae3b
parent 7c3f421e392337f4c3c58e8778526574c23fb532
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue, 27 Feb 2024 13:29:40 +0000

1 Random Problem

Diffstat:
AProblems/0991.cpp | 14++++++++++++++
MREADME.md | 1+
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/Problems/0991.cpp b/Problems/0991.cpp @@ -0,0 +1,14 @@ +class Solution { + public: + int brokenCalc(const int startValue, int target) const { + int res = 0; + while (target > startValue) { + res++; + if (target % 2 == 0) + target /= 2; + else + target++; + } + return res + (startValue - target); + } +}; diff --git a/README.md b/README.md @@ -568,6 +568,7 @@ for solving problems. | 0986 | Medium | [Interval List Intersections](Problems/0986.cpp) | | 0989 | Easy | [Add to Array-Form of Integer](Problems/0989.cpp) | | 0990 | Medium | [Satisfiability of Equality Equations](Problems/0990.cpp) | +| 0991 | Medium | [Broken Calculator](Problems/0991.cpp) | | 0992 | Hard | [Subarrays with K Different Integers](Problems/0992.cpp) | | 0993 | Easy | [Cousins in Binary Tree](Problems/0993.cpp) | | 0994 | Medium | [Rotting Oranges](Problems/0994.cpp) |