This commit is contained in:
2022-11-30 18:20:36 +08:00
parent b13cfa00bb
commit 72555b19e0
132 changed files with 332 additions and 334 deletions

View File

@@ -5,6 +5,6 @@
TEST(Offer05, Case1) {
string s{"We are happy."};
string expected{"We%20are%20happy."};
Solution solution;
Offer05 solution;
EXPECT_EQ(solution.replaceSpace(s), expected);
}

View File

@@ -6,7 +6,7 @@ TEST(Offer58, Case1) {
string s{"abcdefg"};
int k{2};
string expected{"cdefgab"};
Solution solution;
Offer58 solution;
EXPECT_EQ(solution.reverseLeftWords(s, k), expected);
}
@@ -14,6 +14,6 @@ TEST(Offer58, Case2) {
string s{"lrloseumgh"};
int k{6};
string expected{"umghlrlose"};
Solution solution;
Offer58 solution;
EXPECT_EQ(solution.reverseLeftWords(s, k), expected);
}

View File

@@ -6,7 +6,7 @@
TEST(Problem1, Case1) {
std::vector<int> input1{ 2, 7, 11, 15 };
int input2{ 9 };
Solution solution;
S0001 solution;
std::vector<int> result = solution.twoSum(input1, input2);
std::vector<int> answer = std::vector<int>{ 0, 1 };
EXPECT_EQ(result, answer);
@@ -15,7 +15,7 @@ TEST(Problem1, Case1) {
TEST(Problem1, Case2) {
std::vector<int> input1{ 3, 2, 4 };
int input2{ 6 };
Solution solution;
S0001 solution;
std::vector<int> result = solution.twoSum(input1, input2);
std::vector<int> answer = std::vector<int>{ 1, 2 };
EXPECT_EQ(result, answer);
@@ -24,7 +24,7 @@ TEST(Problem1, Case2) {
TEST(Problem1, Case3) {
std::vector<int> input1{ 3, 3 };
int input2{ 6 };
Solution solution;
S0001 solution;
std::vector<int> result = solution.twoSum(input1, input2);
std::vector<int> answer = std::vector<int>{ 0, 1 };
EXPECT_EQ(result, answer);

View File

@@ -11,7 +11,7 @@ TEST(Problem2, Case1) {
new ListNode(5,
new ListNode(6,
new ListNode(4)));
Solution solution;
S0002 solution;
ListNode *l = solution.addTwoNumbers(l1, l2);
EXPECT_EQ(l->val, 7);
EXPECT_EQ(l->next->val, 0);
@@ -21,7 +21,7 @@ TEST(Problem2, Case1) {
TEST(Problem2, Case2) {
ListNode *l1 = new ListNode(0);
ListNode *l2 = new ListNode(0);
Solution solution;
S0002 solution;
ListNode *l = solution.addTwoNumbers(l1, l2);
EXPECT_EQ(l->val, 0);
}
@@ -40,7 +40,7 @@ TEST(Problem2, Case3) {
new ListNode(9,
new ListNode(9,
new ListNode(9))));
Solution solution;
S0002 solution;
ListNode *l = solution.addTwoNumbers(l1, l2);
EXPECT_EQ(l->val, 8);
EXPECT_EQ(l->next->val, 9);

View File

@@ -4,18 +4,18 @@
TEST(Problem3, Case1) {
std::string s{std::string("abcabcbb")};
Solution solution;
S0003 solution;
EXPECT_EQ(solution.lengthOfLongestSubstring(s), 3);
}
TEST(Problem3, Case2) {
std::string s{std::string("bbbbb")};
Solution solution;
S0003 solution;
EXPECT_EQ(solution.lengthOfLongestSubstring(s), 1);
}
TEST(Problem3, Case3) {
std::string s{std::string("pwwkew")};
Solution solution;
S0003 solution;
EXPECT_EQ(solution.lengthOfLongestSubstring(s), 3);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem4, Case1) {
std::vector<int> nums1{1, 3};
std::vector<int> nums2{2};
double answer{2};
Solution solution;
S0004 solution;
EXPECT_EQ(solution.findMedianSortedArrays(nums1, nums2), answer);
}
@@ -14,6 +14,6 @@ TEST(Problem4, Case2) {
std::vector<int> nums1{1, 2};
std::vector<int> nums2{3, 4};
double answer{2.5};
Solution solution;
S0004 solution;
EXPECT_EQ(solution.findMedianSortedArrays(nums1, nums2), answer);
}

View File

@@ -6,17 +6,15 @@ TEST(Problem5, Case1) {
std::string s("babad");
std::string r1("bab");
std::string r2("aba");
Solution1 solution1;
Solution2 solution2;
EXPECT_TRUE(solution1.longestPalindrome(s) == r1 || solution1.longestPalindrome(s) == r2);
EXPECT_TRUE(solution2.longestPalindrome(s) == r1 || solution2.longestPalindrome(s) == r2);
S0005 solution;
EXPECT_TRUE(solution.longestPalindrome1(s) == r1 || solution.longestPalindrome1(s) == r2);
EXPECT_TRUE(solution.longestPalindrome2(s) == r1 || solution.longestPalindrome2(s) == r2);
}
TEST(Problem5, Case2) {
std::string s("cbbd");
std::string r("bb");
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(r.compare(solution1.longestPalindrome(s)), 0);
EXPECT_EQ(r.compare(solution2.longestPalindrome(s)), 0);
S0005 solution;
EXPECT_EQ(r.compare(solution.longestPalindrome1(s)), 0);
EXPECT_EQ(r.compare(solution.longestPalindrome2(s)), 0);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem6, Case1) {
string s("PAYPALISHIRING");
int rows = 3;
string r("PAHNAPLSIIGYIR");
Solution solution;
S0006 solution;
EXPECT_TRUE(solution.convert(s, rows) == r);
}
@@ -14,7 +14,7 @@ TEST(Problem6, Case2) {
string s("PAYPALISHIRING");
int rows = 4;
string r("PINALSIGYAHRPI");
Solution solution;
S0006 solution;
EXPECT_TRUE(solution.convert(s, rows) == r);
}
@@ -22,6 +22,6 @@ TEST(Problem6, Case3) {
string s("AB");
int rows = 4;
string r("AB");
Solution solution;
S0006 solution;
EXPECT_TRUE(solution.convert(s, rows) == r);
}

View File

@@ -5,27 +5,27 @@
TEST(Problem7, Case1) {
int i = 123;
int o = 321;
Solution solution;
S0007 solution;
EXPECT_EQ(solution.reverse(i), o);
}
TEST(Problem7, Case2) {
int i = -123;
int o = -321;
Solution solution;
S0007 solution;
EXPECT_EQ(solution.reverse(i), o);
}
TEST(Problem7, Case3) {
int i = 120;
int o = 21;
Solution solution;
S0007 solution;
EXPECT_EQ(solution.reverse(i), o);
}
TEST(Problem7, Case4) {
int i = -2147483648;
int o = 0;
Solution solution;
S0007 solution;
EXPECT_EQ(solution.reverse(i), o);
}

View File

@@ -5,20 +5,20 @@
TEST(Problem8, Case1) {
string i = std::string("42");
int o = 42;
Solution solution;
S0008 solution;
EXPECT_EQ(solution.myAtoi(i), o);
}
TEST(Problem8, Case2) {
string i = std::string(" -42");
int o = -42;
Solution solution;
S0008 solution;
EXPECT_EQ(solution.myAtoi(i), o);
}
TEST(Problem8, Case3) {
string i = std::string("4193 with words");
int o = 4193;
Solution solution;
S0008 solution;
EXPECT_EQ(solution.myAtoi(i), o);
}

View File

@@ -5,20 +5,20 @@
TEST(Problem9, Case1) {
int i{121};
bool o{true};
Solution solution;
S0009 solution;
EXPECT_EQ(solution.isPalindrome(i), o);
}
TEST(Problem9, Case2) {
int i{-121};
bool o{false};
Solution solution;
S0009 solution;
EXPECT_EQ(solution.isPalindrome(i), o);
}
TEST(Problem9, Case3) {
int i{10};
bool o{false};
Solution solution;
S0009 solution;
EXPECT_EQ(solution.isPalindrome(i), o);
}

View File

@@ -5,20 +5,20 @@
TEST(Problem10, Case1) {
string s{"aa"};
string p{"a"};
Solution solution;
S0010 solution;
EXPECT_FALSE(solution.isMatch(s, p));
}
TEST(Problem10, Case2) {
string s{"aa"};
string p{"a*"};
Solution solution;
S0010 solution;
EXPECT_TRUE(solution.isMatch(s, p));
}
TEST(Problem10, Case3) {
string s{"ab"};
string p{".*"};
Solution solution;
S0010 solution;
EXPECT_TRUE(solution.isMatch(s, p));
}

View File

@@ -5,13 +5,13 @@
TEST(Problem11, Case1) {
vector<int> height{1, 8, 6, 2, 5, 4, 8, 3, 7};
int o{49};
Solution solution;
S0011 solution;
EXPECT_EQ(solution.maxArea(height), o);
}
TEST(Problem11, Case2) {
vector<int> height{1, 1};
int o{1};
Solution solution;
S0011 solution;
EXPECT_EQ(solution.maxArea(height), o);
}

View File

@@ -5,20 +5,20 @@
TEST(Problem12, Case1) {
int i{3};
string o("III");
Solution solution;
S0012 solution;
EXPECT_EQ(solution.intToRoman(i), o);
}
TEST(Problem12, Case2) {
int i{58};
string o("LVIII");
Solution solution;
S0012 solution;
EXPECT_EQ(solution.intToRoman(i), o);
}
TEST(Problem12, Case3) {
int i{1994};
string o("MCMXCIV");
Solution solution;
S0012 solution;
EXPECT_EQ(solution.intToRoman(i), o);
}

View File

@@ -5,20 +5,20 @@
TEST(Problem13, Case1) {
string i("III");
int o{3};
Solution solution;
S0013 solution;
EXPECT_EQ(solution.romanToInt(i), o);
}
TEST(Problem13, Case2) {
string i("LVIII");
int o{58};
Solution solution;
S0013 solution;
EXPECT_EQ(solution.romanToInt(i), o);
}
TEST(Problem13, Case3) {
string i("MCMXCIV");
int o{1994};
Solution solution;
S0013 solution;
EXPECT_EQ(solution.romanToInt(i), o);
}

View File

@@ -5,13 +5,13 @@
TEST(Problem14, Case1) {
vector<string> i{"flower","flow","flight"};
string o{"fl"};
Solution solution;
S0014 solution;
EXPECT_EQ(solution.longestCommonPrefix(i), o);
}
TEST(Problem14, Case2) {
vector<string> i{"dog","racecar","car"};
string o{""};
Solution solution;
S0014 solution;
EXPECT_EQ(solution.longestCommonPrefix(i), o);
}

View File

@@ -6,44 +6,39 @@ TEST(Problem15, Case1) {
vector<int> i{-1, 0, 1, 2, -1, -4};
vector<vector<int>> o1{{-1, -1, 2}, {-1, 0, 1}};
vector<vector<int>> o2{{-1, 0, 1}, {-1, -1, 2}};
Solution1 solution1;
Solution2 solution2;
EXPECT_TRUE(solution1.threeSum(i) == o1 || solution1.threeSum(i) == o2);
EXPECT_TRUE(solution2.threeSum(i) == o1 || solution2.threeSum(i) == o2);
S0015 solution;
EXPECT_TRUE(solution.threeSum1(i) == o1 || solution.threeSum1(i) == o2);
EXPECT_TRUE(solution.threeSum2(i) == o1 || solution.threeSum2(i) == o2);
}
TEST(Problem15, Case2) {
vector<int> i{0, 1, 1};
vector<vector<int>> o{};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.threeSum(i), o);
EXPECT_EQ(solution2.threeSum(i), o);
S0015 solution;
EXPECT_EQ(solution.threeSum1(i), o);
EXPECT_EQ(solution.threeSum2(i), o);
}
TEST(Problem15, Case3) {
vector<int> i{0, 0, 0};
vector<vector<int>> o{{0, 0, 0}};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.threeSum(i), o);
EXPECT_EQ(solution2.threeSum(i), o);
S0015 solution;
EXPECT_EQ(solution.threeSum1(i), o);
EXPECT_EQ(solution.threeSum2(i), o);
}
TEST(Problem15, Case4) {
vector<int> i{-1, 0, 1};
vector<vector<int>> o{{-1, 0, 1}};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.threeSum(i), o);
EXPECT_EQ(solution2.threeSum(i), o);
S0015 solution;
EXPECT_EQ(solution.threeSum1(i), o);
EXPECT_EQ(solution.threeSum2(i), o);
}
TEST(Problem15, Case5) {
vector<int> i{1, 2, -2, -1};
vector<vector<int>> o{};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.threeSum(i), o);
EXPECT_EQ(solution2.threeSum(i), o);
S0015 solution;
EXPECT_EQ(solution.threeSum1(i), o);
EXPECT_EQ(solution.threeSum2(i), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem16, Case1) {
vector<int> nums{-1, 2, 1, -4};
int target{1};
int o{2};
Solution solution;
S0016 solution;
EXPECT_EQ(solution.threeSumClosest(nums, target), o);
}
@@ -14,6 +14,6 @@ TEST(Problem16, Case2) {
vector<int> nums{0, 0, 0};
int target{1};
int o{0};
Solution solution;
S0016 solution;
EXPECT_EQ(solution.threeSumClosest(nums, target), o);
}

View File

@@ -5,20 +5,20 @@
TEST(Problem17, Case1) {
string i{"23"};
vector<string> o{"ad", "bd", "cd", "ae", "be", "ce", "af", "bf", "cf"};
Solution solution;
S0017 solution;
EXPECT_EQ(solution.letterCombinations(i), o);
}
TEST(Problem17, Case2) {
string i{""};
vector<string> o{};
Solution solution;
S0017 solution;
EXPECT_EQ(solution.letterCombinations(i), o);
}
TEST(Problem17, Case3) {
string i{"2"};
vector<string> o{"a", "b", "c"};
Solution solution;
S0017 solution;
EXPECT_EQ(solution.letterCombinations(i), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem18, Case1) {
vector<int> nums{1, 0, -1, 0, -2, 2};
int target{0};
vector<vector<int>> sum{{-2, -1, 1, 2}, {-2, 0, 0, 2}, {-1, 0, 0, 1}};
Solution solution;
S0018 solution;
EXPECT_EQ(solution.fourSum(nums, target), sum);
}
@@ -14,6 +14,6 @@ TEST(Problem18, Case2) {
vector<int> nums{2, 2, 2, 2, 2};
int target{8};
vector<vector<int>> sum{{2, 2, 2, 2}};
Solution solution;
S0018 solution;
EXPECT_EQ(solution.fourSum(nums, target), sum);
}

View File

@@ -5,27 +5,27 @@
TEST(Problem20, Case1) {
string i{"()"};
bool o{true};
Solution solution;
S0020 solution;
EXPECT_EQ(solution.isValid(i), o);
}
TEST(Problem20, Case2) {
string i{"()[]{}"};
bool o{true};
Solution solution;
S0020 solution;
EXPECT_EQ(solution.isValid(i), o);
}
TEST(Problem20, Case3) {
string i{"(]"};
bool o{false};
Solution solution;
S0020 solution;
EXPECT_EQ(solution.isValid(i), o);
}
TEST(Problem20, Case4) {
string i{"(){}}{"};
bool o{false};
Solution solution;
S0020 solution;
EXPECT_EQ(solution.isValid(i), o);
}

View File

@@ -5,20 +5,20 @@
TEST(Problem22, Case1) {
int i{3};
vector<string> o{"((()))", "(()())", "(())()", "()(())", "()()()"};
Solution solution;
S0022 solution;
EXPECT_EQ(solution.generateParenthesis(i), o);
}
TEST(Problem22, Case2) {
int i{1};
vector<string> o{"()"};
Solution solution;
S0022 solution;
EXPECT_EQ(solution.generateParenthesis(i), o);
}
TEST(Problem22, Case3) {
int i{4};
vector<string> o{"(((())))","((()()))","((())())","((()))()","(()(()))","(()()())","(()())()","(())(())","(())()()","()((()))","()(()())","()(())()","()()(())","()()()()"};
Solution solution;
S0022 solution;
EXPECT_EQ(solution.generateParenthesis(i), o);
}

View File

@@ -5,13 +5,13 @@
TEST(Problem26, Case1) {
vector<int> i{1, 1, 2};
int o{2};
Solution solution;
S0026 solution;
EXPECT_EQ(solution.removeDuplicates(i), o);
}
TEST(Problem26, Case2) {
vector<int> i{0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
int o{5};
Solution solution;
S0026 solution;
EXPECT_EQ(solution.removeDuplicates(i), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem27, Case1) {
vector<int> nums{3, 2, 2, 3};
int val{3};
int o{2};
Solution solution;
S0027 solution;
EXPECT_EQ(solution.removeElement(nums, val), o);
}
@@ -14,6 +14,6 @@ TEST(Problem27, Case2) {
vector<int> nums{0, 1, 2, 2, 3, 0, 4, 2};
int val{2};
int o{5};
Solution solution;
S0027 solution;
EXPECT_EQ(solution.removeElement(nums, val), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem28, Case1) {
string haystack{"sadbutsad"};
string needle{"sad"};
int o{0};
Solution solution;
S0028 solution;
EXPECT_EQ(solution.strStr(haystack, needle), o);
}
@@ -14,6 +14,6 @@ TEST(Problem28, Case2) {
string haystack{"leetcode"};
string needle{"leeto"};
int o{-1};
Solution solution;
S0028 solution;
EXPECT_EQ(solution.strStr(haystack, needle), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem29, Case1) {
int dividend{10};
int divisor{3};
int o{3};
Solution solution;
S0029 solution;
EXPECT_EQ(solution.divide(dividend, divisor), o);
}
@@ -14,6 +14,6 @@ TEST(Problem29, Case2) {
int dividend{7};
int divisor{-3};
int o{-2};
Solution solution;
S0029 solution;
EXPECT_EQ(solution.divide(dividend, divisor), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem30, Case1) {
string s{"barfoothefoobarman"};
vector<string> words{"foo", "bar"};
vector<int> o{0, 9};
Solution solution;
S0030 solution;
EXPECT_EQ(solution.findSubstring(s, words), o);
}
@@ -14,6 +14,6 @@ TEST(Problem30, Case2) {
string s{"wordgoodgoodgoodbestword"};
vector<string> words{"word","good","best","word"};
vector<int> o{};
Solution solution;
S0030 solution;
EXPECT_EQ(solution.findSubstring(s, words), o);
}

View File

@@ -5,27 +5,27 @@
TEST(Problem32, Case1) {
string i{"(()"};
int o{2};
Solution solution;
S0032 solution;
EXPECT_EQ(solution.longestValidParentheses(i), o);
}
TEST(Problem32, Case2) {
string i{")()())"};
int o{4};
Solution solution;
S0032 solution;
EXPECT_EQ(solution.longestValidParentheses(i), o);
}
TEST(Problem32, Case3) {
string i{"())"};
int o{2};
Solution solution;
S0032 solution;
EXPECT_EQ(solution.longestValidParentheses(i), o);
}
TEST(Problem32, Case4) {
string i{"()(()"};
int o{2};
Solution solution;
S0032 solution;
EXPECT_EQ(solution.longestValidParentheses(i), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem33, Case1) {
vector<int> nums{4, 5, 6, 7, 0, 1, 2};
int target{0};
int o{4};
Solution solution;
S0033 solution;
EXPECT_EQ(solution.search(nums, target), o);
}
@@ -14,7 +14,7 @@ TEST(Problem33, Case2) {
vector<int> nums{4, 5, 6, 7, 0, 1, 2};
int target{3};
int o{-1};
Solution solution;
S0033 solution;
EXPECT_EQ(solution.search(nums, target), o);
}
@@ -22,6 +22,6 @@ TEST(Problem33, Case3) {
vector<int> nums{1};
int target{0};
int o{-1};
Solution solution;
S0033 solution;
EXPECT_EQ(solution.search(nums, target), o);
}

View File

@@ -6,28 +6,25 @@ TEST(Problem34, Case1) {
vector<int> nums{5, 7, 7, 8, 8, 10};
int target{8};
vector<int> o{3, 4};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.searchRange(nums, target), o);
EXPECT_EQ(solution2.searchRange(nums, target), o);
S0034 solution;
EXPECT_EQ(solution.searchRange1(nums, target), o);
EXPECT_EQ(solution.searchRange2(nums, target), o);
}
TEST(Problem34, Case2) {
vector<int> nums{5, 7, 7, 8, 8, 10};
int target{6};
vector<int> o{-1, -1};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.searchRange(nums, target), o);
EXPECT_EQ(solution2.searchRange(nums, target), o);
S0034 solution;
EXPECT_EQ(solution.searchRange1(nums, target), o);
EXPECT_EQ(solution.searchRange2(nums, target), o);
}
TEST(Problem34, Case3) {
vector<int> nums{};
int target{0};
vector<int> o{-1, -1};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.searchRange(nums, target), o);
EXPECT_EQ(solution2.searchRange(nums, target), o);
S0034 solution;
EXPECT_EQ(solution.searchRange1(nums, target), o);
EXPECT_EQ(solution.searchRange2(nums, target), o);
}

View File

@@ -6,28 +6,25 @@ TEST(Problem35, Case1) {
vector<int> nums{1, 3, 5, 6};
int target{5};
int o{2};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.searchInsert(nums, target), o);
EXPECT_EQ(solution2.searchInsert(nums, target), o);
S0035 solution;
EXPECT_EQ(solution.searchInsert1(nums, target), o);
EXPECT_EQ(solution.searchInsert2(nums, target), o);
}
TEST(Problem35, Case2) {
vector<int> nums{1, 3, 5, 6};
int target{2};
int o{1};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.searchInsert(nums, target), o);
EXPECT_EQ(solution2.searchInsert(nums, target), o);
S0035 solution;
EXPECT_EQ(solution.searchInsert1(nums, target), o);
EXPECT_EQ(solution.searchInsert2(nums, target), o);
}
TEST(Problem35, Case3) {
vector<int> nums{1, 3, 5, 6};
int target{7};
int o{4};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.searchInsert(nums, target), o);
EXPECT_EQ(solution2.searchInsert(nums, target), o);
S0035 solution;
EXPECT_EQ(solution.searchInsert1(nums, target), o);
EXPECT_EQ(solution.searchInsert2(nums, target), o);
}

View File

@@ -13,7 +13,7 @@ TEST(Problem36, Case1) {
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}};
bool o{true};
Solution solution;
S0036 solution;
EXPECT_EQ(solution.isValidSudoku(board), o);
}
@@ -28,6 +28,6 @@ TEST(Problem36, Case2) {
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}};
bool o{false};
Solution solution;
S0036 solution;
EXPECT_EQ(solution.isValidSudoku(board), o);
}

View File

@@ -21,7 +21,7 @@ TEST(Problem37, Case1) {
{'9', '6', '1', '5', '3', '7', '2', '8', '4'},
{'2', '8', '7', '4', '1', '9', '6', '3', '5'},
{'3', '4', '5', '2', '8', '6', '1', '7', '9'}};
Solution solution;
S0037 solution;
solution.solveSudoku(board);
EXPECT_EQ(board, expected);
}

View File

@@ -5,13 +5,13 @@
TEST(Problem38, Case1) {
int i{1};
string o{"1"};
Solution solution;
S0038 solution;
EXPECT_EQ(solution.countAndSay(i), o);
}
TEST(Problem38, Case2) {
int i{4};
string o{"1211"};
Solution solution;
S0038 solution;
EXPECT_EQ(solution.countAndSay(i), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem39, Case1) {
vector<int> candidates{2, 3, 6, 7};
int target{7};
vector<vector<int>> o{{7}, {2, 2, 3}};
Solution solution;
S0039 solution;
EXPECT_EQ(solution.combinationSum(candidates, target), o);
}
@@ -14,7 +14,7 @@ TEST(Problem39, Case2) {
vector<int> candidates{2, 3, 5};
int target{8};
vector<vector<int>> o{{3, 5}, {2, 3, 3}, {2, 2, 2, 2}};
Solution solution;
S0039 solution;
EXPECT_EQ(solution.combinationSum(candidates, target), o);
}
@@ -22,6 +22,6 @@ TEST(Problem39, Case3) {
vector<int> candidates{2};
int target{1};
vector<vector<int>> o{};
Solution solution;
S0039 solution;
EXPECT_EQ(solution.combinationSum(candidates, target), o);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem76, Case1) {
string s{"ADOBECODEBANC"};
string t{"ABC"};
string expected{"BANC"};
Solution solution;
S0076 solution;
EXPECT_EQ(solution.minWindow(s, t), expected);
}
@@ -14,7 +14,7 @@ TEST(Problem76, Case2) {
string s{"a"};
string t{"a"};
string expected{"a"};
Solution solution;
S0076 solution;
EXPECT_EQ(solution.minWindow(s, t), expected);
}
@@ -22,6 +22,6 @@ TEST(Problem76, Case3) {
string s{"a"};
string t{"aa"};
string expected{""};
Solution solution;
S0076 solution;
EXPECT_EQ(solution.minWindow(s, t), expected);
}

View File

@@ -5,27 +5,27 @@
TEST(Problem151, Case1) {
string s{"the sky is blue"};
string expected{"blue is sky the"};
Solution solution;
S0151 solution;
EXPECT_EQ(solution.reverseWords(s), expected);
}
TEST(Problem151, Case2) {
string s{" hello world "};
string expected{"world hello"};
Solution solution;
S0151 solution;
EXPECT_EQ(solution.reverseWords(s), expected);
}
TEST(Problem151, Case3) {
string s{"a good example"};
string expected{"example good a"};
Solution solution;
S0151 solution;
EXPECT_EQ(solution.reverseWords(s), expected);
}
TEST(Problem151, Case4) {
string s{"F R I E N D S "};
string expected{"S D N E I R F"};
Solution solution;
S0151 solution;
EXPECT_EQ(solution.reverseWords(s), expected);
}

View File

@@ -6,7 +6,7 @@ TEST(Problem209, Case1) {
int target{7};
vector<int> nums{2, 3, 1, 2, 4, 3};
int o{2};
Solution solution;
S0209 solution;
EXPECT_EQ(solution.minSubArrayLen(target, nums), o);
}
@@ -14,7 +14,7 @@ TEST(Problem209, Case2) {
int target{4};
vector<int> nums{1, 4, 4};
int o{1};
Solution solution;
S0209 solution;
EXPECT_EQ(solution.minSubArrayLen(target, nums), o);
}
@@ -22,7 +22,7 @@ TEST(Problem209, Case3) {
int target{11};
vector<int> nums{1, 1, 1, 1, 1, 1, 1, 1};
int o{0};
Solution solution;
S0209 solution;
EXPECT_EQ(solution.minSubArrayLen(target, nums), o);
}
@@ -30,6 +30,6 @@ TEST(Problem209, Case4) {
int target{11};
vector<int> nums{1, 2, 3, 4, 5};
int o{3};
Solution solution;
S0209 solution;
EXPECT_EQ(solution.minSubArrayLen(target, nums), o);
}

View File

@@ -5,7 +5,7 @@
TEST(Problem283, Case1) {
vector<int> i{0, 1, 0, 3, 12};
vector<int> o{1, 3, 12, 0, 0};
Solution solution;
S0283 solution;
solution.moveZeroes(i);
EXPECT_EQ(i, o);
}
@@ -13,7 +13,7 @@ TEST(Problem283, Case1) {
TEST(Problem283, Case2) {
vector<int> i{0};
vector<int> o{0};
Solution solution;
S0283 solution;
solution.moveZeroes(i);
EXPECT_EQ(i, o);
}

View File

@@ -6,18 +6,16 @@ TEST(Problem704, Case1) {
vector<int> nums{-1, 0, 3, 5, 9, 12};
int target{9};
int o{4};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.binSearch(nums, target), o);
EXPECT_EQ(solution2.binSearch(nums, target), o);
S0704 solution;
EXPECT_EQ(solution.binSearch1(nums, target), o);
EXPECT_EQ(solution.binSearch2(nums, target), o);
}
TEST(Problem704, Case2) {
vector<int> nums{-1, 0, 3, 5, 9, 12};
int target{2};
int o{-1};
Solution1 solution1;
Solution2 solution2;
EXPECT_EQ(solution1.binSearch(nums, target), o);
EXPECT_EQ(solution2.binSearch(nums, target), o);
S0704 solution;
EXPECT_EQ(solution.binSearch1(nums, target), o);
EXPECT_EQ(solution.binSearch2(nums, target), o);
}