leetcode

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

commit2fb333a7c67424755786d02ebc037d0ccd52feb6
parenta53acfe5ca46bb84aa68ebf00c2c8b4169ef9e2e
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateThu, 7 Dec 2023 14:42:20 +0000

Daily Problem and 1 Random Problem

Diffstat:
AProblems/1903.cpp|+++++++++
AProblems/2423.cpp|+++++++++++++++++++++++++++
MREADME.md|++

3 files changed, 38 insertions(+), 0 deletions(-)


diff --git a/Problems/1903.cpp b/Problems/1903.cpp

@@ -0,0 +1,9 @@

class Solution {
public:
string largestOddNumber(const string &num) const {
for (int i = num.size() - 1; i >= 0; i--) {
if ((num[i] & 0x1F) % 2) return num.substr(0, i + 1);
}
return "";
}
};

diff --git a/Problems/2423.cpp b/Problems/2423.cpp

@@ -0,0 +1,27 @@

class Solution {
int count[27] = {};
bool check(int crnt, int goal) {
for (int j = 1; j <= 26; j++) {
if (crnt == j || !count[j]) continue;
if (goal == -1)
goal = count[j];
else if (count[j] != goal)
return false;
}
return true;
}
public:
bool equalFrequency(const string &word) {
for (const char c : word)
count[c & 0x1F]++;
for (int i = 1; i <= 26; i++) {
if (!count[i]) continue;
const int goal = count[i] > 1 ? count[i] - 1 : -1;
if (check(i, goal)) return true;
}
return false;
}
};

diff --git a/README.md b/README.md

@@ -800,6 +800,7 @@ for solving problems.

| 1884 | Medium | [Egg Drop With 2 Eggs and N Floors](Problems/1884.cpp) |
| 1887 | Medium | [Reduction Operations to Make the Array Elements Equal](Problems/1887.cpp) |
| 1899 | Medium | [Merge Triplets to Form Target Triplet](Problems/1899.cpp) |
| 1903 | Easy | [Largest Odd Number in String](Problems/1903.cpp) |
| 1905 | Medium | [Count Sub Islands](Problems/1905.cpp) |
| 1910 | Medium | [Remove All Occurrences of a Substring](Problems/1910.cpp) |
| 1921 | Medium | [Eliminate Maximum Number of Monsters](Problems/1921.cpp) |

@@ -901,6 +902,7 @@ for solving problems.

| 2410 | Medium | [Maximum Matching of Players With Trainers](Problems/2410.cpp) |
| 2415 | Medium | [Reverse Odd Levels of Binary Tree](Problems/2415.cpp) |
| 2421 | Medium | [Number of Good Paths](Problems/2421.cpp) |
| 2423 | Easy | [Remove Letter To Equalize Frequency](Problems/2423.cpp) |
| 2428 | Medium | [Maximum Sum of an Hourglass](Problems/2428.cpp) |
| 2433 | Medium | [Find The Original Array of Prefix Xor](Problems/2433.cpp) |
| 2439 | Medium | [Minimize Maximum of Array](Problems/2439.cpp) |