mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
Refactor almost everything
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
public:
|
||||
int maxArea(std::vector<int> &height) {
|
||||
int left = 0;
|
||||
int right = height.size() - 1;
|
||||
|
||||
@@ -9,7 +9,7 @@ struct TreeNode {
|
||||
};
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
public:
|
||||
TreeNode *insertIntoBST(TreeNode *root, int val) {
|
||||
TreeNode *node = root;
|
||||
while (node != nullptr) {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
public:
|
||||
std::vector<std::string> letterCombinations(std::string digits) {
|
||||
std::string letters[] = {"abc", "def", "ghi", "jkl",
|
||||
std::string letters[] = {"abc", "def", "ghi", "jkl",
|
||||
"mno", "pqrs", "tuv", "wxyz"};
|
||||
|
||||
std::vector<std::string> finvec;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <string>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
public:
|
||||
std::string longestPalindrome(std::string line) {
|
||||
if (line.size() < 2) {
|
||||
return line;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
private:
|
||||
private:
|
||||
bool binarySearch(std::vector<int> &nums, int start, int end, int target) {
|
||||
while (end >= start) {
|
||||
int middle = start + (end - start) / 2;
|
||||
@@ -36,7 +36,7 @@ class Solution {
|
||||
}
|
||||
*/
|
||||
|
||||
public:
|
||||
public:
|
||||
bool searchMatrix(std::vector<std::vector<int>> &matrix, int target) {
|
||||
int row = matrix.size();
|
||||
int col = matrix[0].size();
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ListNode {
|
||||
int val;
|
||||
struct ListNode *next;
|
||||
};
|
||||
|
||||
struct ListNode *merge(struct ListNode *left, struct ListNode *right) {
|
||||
if (!left) {
|
||||
return right;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <string>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
public:
|
||||
int myAtoi(std::string s) {
|
||||
|
||||
unsigned long value = 0;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
public:
|
||||
std::vector<int> twoSum(std::vector<int> &numbers, int target) {
|
||||
int j = -1;
|
||||
for (int i = 0; i < numbers.size(); ++i) {
|
||||
@@ -8,14 +10,15 @@ class Solution {
|
||||
j = binarySearch(numbers, 0, numbers.size() - 1, otherhalf);
|
||||
|
||||
if (j != -1 && i != j) {
|
||||
if (i < j)
|
||||
return std::vector{i + 1, j + 1};
|
||||
else
|
||||
return std::vector{j + 1, i + 1};
|
||||
if (i < j) {
|
||||
return {i + 1, j + 1};
|
||||
} else {
|
||||
return {j + 1, i + 1};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::vector{-1, -1};
|
||||
return {-1, -1};
|
||||
}
|
||||
|
||||
int binarySearch(std::vector<int> &numbers, int start, int end, int key) {
|
||||
|
||||
Reference in New Issue
Block a user