leetcode

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

commit 8a15eeefca249944913f0e92df9231e6bcf8bb1b
parent 43747ad4054b3742f2845f849b010416973925b2
author Dimitrije Dobrota <mail@dimitrijedobrota.com>
date Fri, 28 Jun 2024 08:14:40 +0200

1 Random Problem

Diffstat:
A Problems/2222.cpp | ++++++++++++++++++++++++
M README.md | +

2 files changed, 25 insertions(+), 0 deletions(-)


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

@@ -0,0 +1,24 @@
class Solution {
public:
long long numberOfWays(const string &s) const {
static int count[100001];
const int n = size(s);
int crnt[] = {0, 0};
long long res = 0;
for (int i = n - 1; i >= 0; i--) {
const int idx = s[i] - '0';
count[i] = crnt[!idx];
crnt[idx]++;
}
crnt[0] = crnt[1] = 0;
for (int i = 0; i < n; i++) {
const int idx = s[i] - '0';
res += count[i] * crnt[!idx];
crnt[idx]++;
}
return res;
}
};

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

@@ -1086,6 +1086,7 @@ for solving problems. | 2215 | Easy | [Find the Difference of Two Arrays](Problems/2215.cpp) | | 2218 | Hard | [Maximum Value of K Coins From Piles](Problems/2218.cpp) | | 2221 | Medium | [Find Triangular Sum of an Array](Problems/2221.cpp) |
| 2222 | Medium | [Number of Ways to Select Buildings](Problems/2222.cpp) |
| 2225 | Medium | [Find Players With Zero or One Losses](Problems/2225.cpp) | | 2232 | Medium | [Minimize Result by Adding Parentheses to Expression](Problems/2232.cpp) | | 2235 | Easy | [Add Two Integers](Problems/2235.cpp) |