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,7 +5,7 @@
using namespace std;
class Solution {
class Offer05 {
public:
string replaceSpace(string s);
};

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class Offer58 {
public:
string reverseLeftWords(string s, int n);
void reverseSubStr(string &s, int begin, int end);

View File

@@ -5,7 +5,9 @@
#include <unordered_map>
#include <vector>
class Solution {
using namespace std;
class S0001 {
public:
/**
* @brief Two Sum

View File

@@ -9,7 +9,7 @@ struct ListNode {
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class Solution {
class S0002 {
public:
/**
* @brief Add Two Numbers

View File

@@ -4,7 +4,9 @@
#include <map>
#include <string>
class Solution {
using namespace std;
class S0003 {
public:
/**
* @brief Longest Substring Without Repeating Characters

View File

@@ -3,7 +3,9 @@
#include <vector>
class Solution {
using namespace std;
class S0004 {
public:
/**
* @brief Median of Two Sorted Arrays

View File

@@ -1,26 +1,20 @@
#ifndef S0005_LONGEST_PALINDROMIC_SUBSTRING_HPP
#define S0005_LONGEST_PALINDROMIC_SUBSTRING_HPP
#include <string>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
class Solution1 {
public:
/**
* @brief Longest Palindromic Substring
*
* Given a string s, return the longest palindromic substring in s.
*
* @param s the given string
* @return longest palindromic substring
*/
string longestPalindrome(string s);
};
typedef struct S0005ResultStruct {
int left1; // 边界情况为长度为 1 的字符时,扩展完成后的左边界
int right1; // 边界情况为长度为 1 的字符时,扩展完成后的右边界
int left2; // 边界情况为长度为 2 的字符串时,扩展完成后的左边界
int right2; // 边界情况为长度为 2 的字符串时,扩展完成后的右边界
} S0005Result;
class Solution2 {
class S0005 {
public:
/**
* @brief Longest Palindromic Substring
@@ -30,7 +24,17 @@ class Solution2 {
* @param s the given string
* @return longest palindromic substring
*/
string longestPalindrome(string s);
string longestPalindrome1(string s);
/**
* @brief Longest Palindromic Substring
*
* Given a string s, return the longest palindromic substring in s.
*
* @param s the given string
* @return longest palindromic substring
*/
string longestPalindrome2(string s);
S0005Result expand(string s, int i);
};
#endif

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0006 {
public:
/**
* @brief Zigzag Conversion

View File

@@ -5,7 +5,9 @@
#include <cmath>
#include <climits>
class Solution {
using namespace std;
class S0007 {
public:
int reverse(int x);
};

View File

@@ -8,7 +8,7 @@
using namespace std;
class Solution {
class S0008 {
public:
int myAtoi(string s);
};

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0009 {
public:
bool isPalindrome(int x);
};

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0010 {
public:
bool isMatch(string s, string p);
};

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0011 {
public:
int maxArea(vector<int>& height);
};

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0012 {
public:
string intToRoman(int num);
};

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0013 {
public:
int romanToInt(string s);
};

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0014 {
public:
string longestCommonPrefix(vector<string>& strs);
};

View File

@@ -7,14 +7,10 @@
using namespace std;
class Solution1 {
class S0015 {
public:
vector<vector<int>> threeSum(vector<int>& nums);
};
class Solution2 {
public:
vector<vector<int>> threeSum(vector<int>& nums);
vector<vector<int>> threeSum1(vector<int>& nums);
vector<vector<int>> threeSum2(vector<int>& nums);
};
#endif

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0016 {
public:
int threeSumClosest(vector<int>& nums, int target);
};

View File

@@ -7,7 +7,7 @@
using namespace std;
class Solution {
class S0017 {
public:
vector<string> letterCombinations(string digits);
};

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0018 {
public:
vector<vector<int>> fourSum(vector<int>& nums, int target);
};

View File

@@ -9,7 +9,7 @@ struct ListNode {
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class Solution {
class S0019 {
public:
ListNode* removeNthFromEnd(ListNode* head, int n);
};

View File

@@ -6,9 +6,10 @@
using namespace std;
class Solution {
class S0020 {
public:
bool isValid(string s);
bool match(string s1, string s2);
};
#endif

View File

@@ -1,6 +1,10 @@
#ifndef S0021_MERGE_TWO_SORTED_LISTS_HPP
#define S0021_MERGE_TWO_SORTED_LISTS_HPP
#include <limits>
using namespace std;
struct ListNode {
int val;
ListNode* next;
@@ -9,9 +13,7 @@ struct ListNode {
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
#include <limits>
class Solution {
class S0021 {
public:
ListNode* mergeTwoLists(ListNode* list1, ListNode* list2);
};

View File

@@ -7,9 +7,10 @@
using namespace std;
class Solution {
class S0022 {
public:
vector<string> generateParenthesis(int n);
void dfs(string current, int left, int right, vector<string> &result);
};
#endif

View File

@@ -7,15 +7,17 @@ using namespace std;
struct ListNode {
int val;
ListNode* next;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
class Solution {
class S0023 {
public:
ListNode* mergeKLists(vector<ListNode*>& lists);
ListNode *mergeKLists(vector<ListNode *> &lists);
ListNode *mergeTwoLists(ListNode *a, ListNode *b);
ListNode *merge(vector<ListNode *> &lists, int l, int r);
};
#endif

View File

@@ -9,7 +9,7 @@ struct ListNode {
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class Solution {
class S0024 {
public:
ListNode* swapPairs(ListNode* head);
};

View File

@@ -1,8 +1,8 @@
#ifndef S0025_REVERSE_NODES_IN_K_GROUP_HPP
#define S0025_REVERSE_NODES_IN_K_GROUP_HPP
#include <utility>
#include <tuple>
#include <utility>
using namespace std;
@@ -14,9 +14,10 @@ struct ListNode {
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class Solution {
class S0025 {
public:
ListNode* reverseKGroup(ListNode* head, int k);
pair<ListNode*, ListNode*> myReverse(ListNode* head, ListNode* tail);
};
#endif

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0026 {
public:
int removeDuplicates(vector<int>& nums);
};

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0027 {
public:
int removeElement(vector<int>& nums, int val);
};

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0028 {
public:
int strStr(string haystack, string needle);
};

View File

@@ -3,9 +3,12 @@
#include <climits>
class Solution {
using namespace std;
class S0029 {
public:
int divide(int dividend, int divisor);
int div(long a, long b);
};
#endif

View File

@@ -7,7 +7,7 @@
using namespace std;
class Solution {
class S0030 {
public:
vector<int> findSubstring(string s, vector<string>& words);
};

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0031 {
public:
void nextPermutation(vector<int>& nums);
};

View File

@@ -7,7 +7,7 @@
using namespace std;
class Solution {
class S0032 {
public:
int longestValidParentheses(string s);
};

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0033 {
public:
int search(vector<int>& nums, int target);
};

View File

@@ -5,13 +5,10 @@
using namespace std;
class Solution1 {
class S0034 {
public:
vector<int> searchRange(vector<int>& nums, int target);
vector<int> searchRange1(vector<int>& nums, int target);
vector<int> searchRange2(vector<int>& nums, int target);
};
class Solution2 {
public:
vector<int> searchRange(vector<int>& nums, int target);
};
#endif

View File

@@ -5,14 +5,10 @@
using namespace std;
class Solution1 {
class S0035 {
public:
int searchInsert(vector<int>& nums, int target);
};
class Solution2 {
public:
int searchInsert(vector<int>& nums, int target);
int searchInsert1(vector<int>& nums, int target);
int searchInsert2(vector<int>& nums, int target);
};
#endif

View File

@@ -7,7 +7,7 @@
using namespace std;
class Solution {
class S0036 {
public:
bool isValidSudoku(vector<vector<char>>& board);
};

View File

@@ -1,16 +1,21 @@
#ifndef S0037_SUDOKU_SOLVER_HPP
#define S0037_SUDOKU_SOLVER_HPP
#include <vector>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <vector>
using namespace std;
class Solution {
class S0037 {
public:
void solveSudoku(vector<vector<char>>& board);
void solveSudoku(vector<vector<char>> &board);
bool recusiveSolveSudoku(vector<vector<char>> &board,
vector<unordered_map<char, bool>> &rows,
vector<unordered_map<char, bool>> &cols,
vector<unordered_map<char, bool>> &grids, int row,
int col);
};
#endif

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0038 {
public:
string countAndSay(int n);
};

View File

@@ -1,15 +1,17 @@
#ifndef S0039_COMBINATION_SUM_HPP
#define S0039_COMBINATION_SUM_HPP
#include <vector>
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
class Solution {
class S0039 {
public:
vector<vector<int>> combinationSum(vector<int>& candidates, int target);
void dfs(vector<int>& candidates, int target, vector<vector<int>>& ans,
vector<int>& combine, int idx);
};
#endif

View File

@@ -7,7 +7,7 @@
using namespace std;
class Solution {
class S0076 {
public:
string minWindow(string s, string t);
unordered_map<char, int> ori, cnt;

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0151 {
public:
void reverseSubStr(string &s, int begin, int end);
string reverseWords(string s);

View File

@@ -6,7 +6,7 @@
using namespace std;
class Solution {
class S0209 {
public:
int minSubArrayLen(int target, vector<int>& nums);
};

View File

@@ -5,7 +5,7 @@
using namespace std;
class Solution {
class S0283 {
public:
void moveZeroes(vector<int>& nums);
};

View File

@@ -5,14 +5,10 @@
using namespace std;
class Solution1 {
class S0704 {
public:
int binSearch(vector<int>& nums, int target);
};
class Solution2 {
public:
int binSearch(vector<int>& nums, int target);
int binSearch1(vector<int>& nums, int target);
int binSearch2(vector<int>& nums, int target);
};
#endif