leetcode

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

commit dc4b4db87436e611f1a3466b93d61b0e7c57dfb9
parent 57c5f7030c9da7fa303bdbff777c2bc433641256
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 14 Apr 2023 13:54:36 +0200

Random Problem

Diffstat:
AProblems/0165.cpp | 25+++++++++++++++++++++++++
MREADME.md | 1+
2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/Problems/0165.cpp b/Problems/0165.cpp @@ -0,0 +1,25 @@ +class Solution { +public: + int compareVersion(string version1, string version2) { + stringstream s1(version1), s2(version2); + vector<int> v1, v2; + + string crnt; + while (getline(s1, crnt, '.')) v1.push_back(stoi(crnt)); + while (getline(s2, crnt, '.')) v2.push_back(stoi(crnt)); + + while (v1.size() < v2.size()) v1.push_back(0); + while (v1.size() > v2.size()) v2.push_back(0); + + int i = 0, j = 0; + while (i < v1.size() && j < v2.size()) { + if (v1[i] > v2[j]) return 1; + if (v1[i] < v2[j]) + return -1; + else + i++, j++; + } + + return 0; + } +}; diff --git a/README.md b/README.md @@ -158,6 +158,7 @@ for solving problems. | 0160 | Easy | [Intersection of Two Linked Lists](Problems/0160.cpp) | | 0162 | Medium | [Find Peak Element](Problems/0162.cpp) | | 0164 | Hard | [Maximum Gap](Problems/0164.cpp) | +| 0165 | Medium | [Compare Version Numbers](Problems/0165.cpp) | | 0167 | Medium | [Two Sum II - Input Array Is Sorted](Problems/0167.cpp) | | 0168 | Easy | [Excel Sheet Column Title](Problems/0168.cpp) | | 0169 | Easy | [Majority Element](Problems/0169.cpp) |