Refactor
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class Offer05 {
|
||||
public:
|
||||
string replaceSpace(string s);
|
||||
};
|
||||
|
@@ -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);
|
||||
|
@@ -5,7 +5,9 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
using namespace std;
|
||||
|
||||
class S0001 {
|
||||
public:
|
||||
/**
|
||||
* @brief Two Sum
|
||||
|
@@ -9,7 +9,7 @@ struct ListNode {
|
||||
ListNode(int x, ListNode* next) : val(x), next(next) {}
|
||||
};
|
||||
|
||||
class Solution {
|
||||
class S0002 {
|
||||
public:
|
||||
/**
|
||||
* @brief Add Two Numbers
|
||||
|
@@ -4,7 +4,9 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class Solution {
|
||||
using namespace std;
|
||||
|
||||
class S0003 {
|
||||
public:
|
||||
/**
|
||||
* @brief Longest Substring Without Repeating Characters
|
||||
|
@@ -3,7 +3,9 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
using namespace std;
|
||||
|
||||
class S0004 {
|
||||
public:
|
||||
/**
|
||||
* @brief Median of Two Sorted Arrays
|
||||
|
@@ -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
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0006 {
|
||||
public:
|
||||
/**
|
||||
* @brief Zigzag Conversion
|
||||
|
@@ -5,7 +5,9 @@
|
||||
#include <cmath>
|
||||
#include <climits>
|
||||
|
||||
class Solution {
|
||||
using namespace std;
|
||||
|
||||
class S0007 {
|
||||
public:
|
||||
int reverse(int x);
|
||||
};
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0008 {
|
||||
public:
|
||||
int myAtoi(string s);
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0009 {
|
||||
public:
|
||||
bool isPalindrome(int x);
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0010 {
|
||||
public:
|
||||
bool isMatch(string s, string p);
|
||||
};
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0011 {
|
||||
public:
|
||||
int maxArea(vector<int>& height);
|
||||
};
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0012 {
|
||||
public:
|
||||
string intToRoman(int num);
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0013 {
|
||||
public:
|
||||
int romanToInt(string s);
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0014 {
|
||||
public:
|
||||
string longestCommonPrefix(vector<string>& strs);
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0016 {
|
||||
public:
|
||||
int threeSumClosest(vector<int>& nums, int target);
|
||||
};
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0017 {
|
||||
public:
|
||||
vector<string> letterCombinations(string digits);
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0018 {
|
||||
public:
|
||||
vector<vector<int>> fourSum(vector<int>& nums, int target);
|
||||
};
|
||||
|
@@ -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);
|
||||
};
|
||||
|
@@ -6,9 +6,10 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0020 {
|
||||
public:
|
||||
bool isValid(string s);
|
||||
bool match(string s1, string s2);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -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);
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -9,7 +9,7 @@ struct ListNode {
|
||||
ListNode(int x, ListNode* next) : val(x), next(next) {}
|
||||
};
|
||||
|
||||
class Solution {
|
||||
class S0024 {
|
||||
public:
|
||||
ListNode* swapPairs(ListNode* head);
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0026 {
|
||||
public:
|
||||
int removeDuplicates(vector<int>& nums);
|
||||
};
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0027 {
|
||||
public:
|
||||
int removeElement(vector<int>& nums, int val);
|
||||
};
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0028 {
|
||||
public:
|
||||
int strStr(string haystack, string needle);
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0030 {
|
||||
public:
|
||||
vector<int> findSubstring(string s, vector<string>& words);
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0031 {
|
||||
public:
|
||||
void nextPermutation(vector<int>& nums);
|
||||
};
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0032 {
|
||||
public:
|
||||
int longestValidParentheses(string s);
|
||||
};
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0033 {
|
||||
public:
|
||||
int search(vector<int>& nums, int target);
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0036 {
|
||||
public:
|
||||
bool isValidSudoku(vector<vector<char>>& board);
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0038 {
|
||||
public:
|
||||
string countAndSay(int n);
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0076 {
|
||||
public:
|
||||
string minWindow(string s, string t);
|
||||
unordered_map<char, int> ori, cnt;
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0151 {
|
||||
public:
|
||||
void reverseSubStr(string &s, int begin, int end);
|
||||
string reverseWords(string s);
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0209 {
|
||||
public:
|
||||
int minSubArrayLen(int target, vector<int>& nums);
|
||||
};
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
class S0283 {
|
||||
public:
|
||||
void moveZeroes(vector<int>& nums);
|
||||
};
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user