Refactor almost everything

This commit is contained in:
Arkaprabha Chakraborty
2022-08-02 12:21:43 +05:30
parent ccc376aea0
commit cab1180397
39 changed files with 117 additions and 54 deletions

View File

@@ -2,7 +2,7 @@
#include <vector>
class Solution {
public:
public:
int maxArea(std::vector<int> &height) {
int left = 0;
int right = height.size() - 1;

View File

@@ -9,7 +9,7 @@ struct TreeNode {
};
class Solution {
public:
public:
TreeNode *insertIntoBST(TreeNode *root, int val) {
TreeNode *node = root;
while (node != nullptr) {

View File

@@ -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;

View File

@@ -1,7 +1,7 @@
#include <string>
class Solution {
public:
public:
std::string longestPalindrome(std::string line) {
if (line.size() < 2) {
return line;

View File

@@ -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();

View File

@@ -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;

View File

@@ -1,5 +1,7 @@
#include <string>
class Solution {
public:
public:
int myAtoi(std::string s) {
unsigned long value = 0;

View File

@@ -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) {