Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
zotvent committed Sep 18, 2022
1 parent 3a4a993 commit 5bbd76c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
18 changes: 5 additions & 13 deletions leetcode/algorithms/383 - Ransom Note.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
vector<int> r(26, 0), m(26, 0);
vector<int> freq(26, 0);

for (auto i: ransomNote) {
r[i - 'a']++;
}

for (auto i: magazine) {
m[i - 'a']++;
}

for (int i = 0; i < r.size(); i++) {
if (r[i] > m[i]) {
return false;
}
for (auto& i: magazine) freq[i - 'a']++;
for (auto& i: ransomNote) freq[i - 'a']--;
for (auto& i: freq) {
if (i < 0) return false;
}

return true;
Expand Down
16 changes: 16 additions & 0 deletions leetcode/algorithms/62 - Unique Paths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
int uniquePaths(int m, int n) {
vector<vector<int>> dp(m, vector<int>(n, 0));
dp[0][0] = 1;

for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (i > 0) dp[i][j] += dp[i - 1][j];
if (j > 0) dp[i][j] += dp[i][j - 1];
}
}

return dp[m - 1][n - 1];
}
};

0 comments on commit 5bbd76c

Please sign in to comment.