Skip to content

Commit

Permalink
Fix typo in test fixing build and warning fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
iglesias committed Jul 8, 2024
1 parent e7a4824 commit 905fdcc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions leetcode/131.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ bool is_palindrome(const string& s, int start, int end) {
return true;
}

void solve(const string& s, vector<vector<string>>& ans, vector<int>& v, int v_index = 0) {
void solve(const string& s, vector<vector<string>>& ans, vector<int>& v, size_t v_index = 0) {
if (!v.size()) {
if (is_palindrome(s, 0, s.length() - 1)) ans.push_back(vector<string>{s});
if (is_palindrome(s, 0, static_cast<int>(s.length()) - 1)) ans.push_back(vector<string>{s});
} else {
bool not_palindrome_found = false;
int start = 0;
Expand All @@ -23,19 +23,20 @@ void solve(const string& s, vector<vector<string>>& ans, vector<int>& v, int v_i
candidate.push_back(s.substr(start, v[i] - start + 1));
start = v[i] + 1;
}
not_palindrome_found |= !is_palindrome(s, start, s.length() - 1);
not_palindrome_found |= !is_palindrome(s, start, static_cast<int>(s.length()) - 1);
candidate.push_back(s.substr(start));
if (!not_palindrome_found) ans.push_back(candidate);
}
for (size_t j = v_index; j < s.length() - 1; j++) {
v.push_back(j);
v.push_back(static_cast<int>(j));
solve(s, ans, v, j + 1);
v.pop_back();
}
}

vector<vector<string>> partition(const string& s) {
vector<vector<string>> ans;
if (!s.length()) return ans;
vector<int> v;
solve(s, ans, v);
return ans;
Expand Down
2 changes: 1 addition & 1 deletion leetcode/140.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ vector<string> wordbreak(const string& s, const vector<string>& wordDict) {
TEST(BreakIntoWords, Example_1)
{
EXPECT_EQ(wordbreak("catsanddog", vector<string>{"cat", "cats", "and", "sand", "dog"}),
vector<string>{"cat sand dog", "cats and dog"});
(vector<string>{"cat sand dog", "cats and dog"}));
}

int main(int argc, char **argv)
Expand Down
2 changes: 1 addition & 1 deletion leetcode/1404.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

int solve(std::string s)
{
int l = 0, r = s.length() - 1;
int l = 0, r = static_cast<int>(s.length()) - 1;
int ans = 0;
while (l < r) {
ans++;
Expand Down
2 changes: 1 addition & 1 deletion leetcode/3012.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ template<typename Range> constexpr int solve(const Range& nums){
for(const auto num : nums) if((num % min) != 0) return 1;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshift-op-parentheses"
return min_count + 1 >> 1;
return (static_cast<int>(min_count) + 1) >> 1;
#pragma clang diagnostic pop
}

Expand Down
6 changes: 3 additions & 3 deletions leetcode/995.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Solution {
for (size_t i = 0; i < nums.size() && !stop; i += 2) if ( nums[i]) stop = true;
for (size_t i = 1; i < nums.size() && !stop; i += 2) if (!nums[i]) stop = true;
if (!stop && !(nums.size() % 2)) {
if (k == nums.size()) return -1;
if (!(nums.size() % k)) return nums.size() / 2;
if (k == static_cast<int>(nums.size())) return -1;
if (!(nums.size() % k)) return static_cast<int>(nums.size()) / 2;
return -1;
}
}
Expand All @@ -35,7 +35,7 @@ class Solution {
while (i < nums.size()) {
while (i < nums.size() - k and nums[i]) i++;
if (i >= nums.size() - k) {
const int backup = i;
const size_t backup = i;
if (!nums[i]) { while (i < nums.size()) if ( nums[i++]) return -1; }
else { while (i < nums.size()) if (!nums[i++]) return -1; }
return ans + !nums[backup];
Expand Down

0 comments on commit 905fdcc

Please sign in to comment.