leetcode

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

commit 534f9506f11b33e1aff4e245ecbe25a6dbe1588d
parent 1911873b6e9970e7cb068bc3f6fc6c16037cb1de
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 11 Mar 2023 18:19:33 +0100

Random Problem

Diffstat:
AProblems/0058.cpp | 10++++++++++
MREADME.md | 1+
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/Problems/0058.cpp b/Problems/0058.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + int lengthOfLastWord(string s) { + int i = s.size(), res = 0; + while (--i >= 0 && isspace(s[i])) + ; + while (i >= 0 && !isspace(s[i--])) res++; + return res; + } +}; diff --git a/README.md b/README.md @@ -68,6 +68,7 @@ for solving problems. | 0055 | Medium | [Jump Game](Problems/0055.cpp) | | 0056 | Medium | [Merge Intervals](Problems/0056.cpp) | | 0057 | Medium | [Insert Interval](Problems/0057.cpp) | +| 0058 | Easy | [Length of Last Word](Problems/0058.cpp) | | 0059 | Medium | [Spiral Matrix II](Problems/0059.cpp) | | 0061 | Medium | [Rotate List](Problems/0061.cpp) | | 0062 | Medium | [Unique Paths](Problems/0062.cpp) |