leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 57fb1fbf59c96003141dd02b1ba506be1c0f196e |
parent | 9123a59902cfb1fef47d1e08205c612b35d2e8b9 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sat, 9 Mar 2024 12:03:36 +0000 |
Daily Problem and 1 Random Problem
Diffstat:A | Problems/0357.cpp | | | ++++++++++++ |
A | Problems/2540.cpp | | | +++++++++++++++++ |
M | README.md | | | ++ |
3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/Problems/0357.cpp b/Problems/0357.cpp
@@ -0,0 +1,12 @@
class Solution {
public:
int countNumbersWithUniqueDigits(const int n) const {
if (n == 0) return 1;
int res = 10, acc = 9, crnt = 9;
for (int i = 2; i <= n; i++)
res += acc *= crnt--;
return res;
}
};
diff --git a/Problems/2540.cpp b/Problems/2540.cpp
@@ -0,0 +1,17 @@
class Solution {
public:
int getCommon(const vector<int> &nums1, const vector<int> &nums2) const {
const int n = size(nums1), m = size(nums2);
int i = 0, j = 0;
while (i < n && j < m) {
if (nums1[i] == nums2[j]) return nums1[i];
if (nums1[i] > nums2[j])
j++;
else
i++;
}
return -1;
}
};
diff --git a/README.md b/README.md
@@ -284,6 +284,7 @@ for solving problems.
| 0347 | Medium | [Top K Frequent Elements](Problems/0347.cpp) |
| 0350 | Easy | [Intersection of Two Arrays II](Problems/0350.cpp) |
| 0352 | Hard | [Data Stream as Disjoint Intervals](Problems/0352.cpp) |
| 0357 | Medium | [Count Numbers with Unique Digits](Problems/0357.cpp) |
| 0367 | Easy | [Valid Perfect Square](Problems/0367.cpp) |
| 0368 | Medium | [Largest Divisible Subset](Problems/0368.cpp) |
| 0371 | Medium | [Sum of Two Integers](Problems/0371.cpp) |
@@ -1087,6 +1088,7 @@ for solving problems.
| 2498 | Medium | [Frog Jump II](Problems/2498.cpp) |
| 2517 | Medium | [Maximum Tastiness of Candy Basket](Problems/2517.cpp) |
| 2527 | Medium | [Find Xor-Beauty of Array](Problems/2527.cpp) |
| 2540 | Easy | [Minimum Common Value](Problems/2540.cpp) |
| 2542 | Medium | [Maximum Subsequence Score](Problems/2542.cpp) |
| 2545 | Medium | [Sort the Students by Their Kth Score](Problems/2545.cpp) |
| 2551 | Hard | [Put Marbles in Bags](Problems/2551.cpp) |