diff --git a/Problems/LeetcodeProblems/1-two-sum.h b/Problems/LeetcodeProblems/1-two-sum.h deleted file mode 100644 index 4bfcb23fa4fdf5a32d2a045e31975b3d07405910..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/1-two-sum.h +++ /dev/null @@ -1,18 +0,0 @@ -class Solution { -public: - vector twoSum(vector& nums, int target) { - vector sum; - for(auto i = 0; i < nums.size(); i++) - { - for(auto j = i+1; j < nums.size(); j++) - { - if(i == j) continue; - if(nums[i] + nums[j] != target) continue; - sum.push_back(i); - sum.push_back(j); - return sum; - } - } - return sum; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/11-container-with-most-water.h b/Problems/LeetcodeProblems/11-container-with-most-water.h deleted file mode 100644 index 54d7f677a4a7ec79f4816e9bfbf575f22bff4325..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/11-container-with-most-water.h +++ /dev/null @@ -1,22 +0,0 @@ -class Solution { -public: - int maxArea(vector& height) { - int left = 0, right = height.size()-1; - int max = 0, temp = 0; - while(left < right) { - temp = (right - left) * (height[left] < height[right] ? height[left] : height[right]); - if(max < temp) max = temp; - if(height[left] < height[right]) { - do{ - left++; - } while(left < right && height[left-1] >= height[left]); - } - else { - do{ - right--; - } while(left < right && height[right] <= height[right+1]); - } - } - return max; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/118-pascals-triangle.h b/Problems/LeetcodeProblems/118-pascals-triangle.h deleted file mode 100644 index 3d89970453d4e07c3f68f543370279089610a263..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/118-pascals-triangle.h +++ /dev/null @@ -1,21 +0,0 @@ -class Solution { -public: - vector> generate(int numRows) { - vector> triangle; - for(int i = 0; i < numRows; i++){ - vector v; - if(i==0){ - v.push_back(1); - } - else{ - v.push_back(1); - for(int j = 0; j < triangle[i-1].size()-1; j++){ - v.push_back(triangle[i-1][j] + triangle[i-1][j+1]); - } - v.push_back(1); - } - triangle.push_back(v); - } - return triangle; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/119-pascals-triangle-ii.h b/Problems/LeetcodeProblems/119-pascals-triangle-ii.h deleted file mode 100644 index 2cb0046948fac2c28bd64df08b0c83d15d17aa7c..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/119-pascals-triangle-ii.h +++ /dev/null @@ -1,13 +0,0 @@ -class Solution { -public: - vector getRow(int rowIndex) { - vector v(rowIndex + 1, 0); - v[0] = 1; - for (int i = 0; i < rowIndex; i++){ - for(int j = i + 1; j > 0; j--){ - v[j] += v[j - 1]; - } - } - return v; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/121-best-time-to-buy-and-sell-stock.h b/Problems/LeetcodeProblems/121-best-time-to-buy-and-sell-stock.h deleted file mode 100644 index fef96f9f143692054d896afafe734205bdac93de..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/121-best-time-to-buy-and-sell-stock.h +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - int left = 0, right = 0; - int max = 0, temp = 0; - for(auto i = 0; i < prices.size(); ++i) { - right = i; - temp = prices[right] - prices[left]; - if(temp < 0) left = i; - if(max < temp) max = temp; - } - return max; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/122-best-time-to-buy-and-sell-stock-ii.h b/Problems/LeetcodeProblems/122-best-time-to-buy-and-sell-stock-ii.h deleted file mode 100644 index 24a9a8d6e265f76bee382c5ce654b07668e10496..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/122-best-time-to-buy-and-sell-stock-ii.h +++ /dev/null @@ -1,26 +0,0 @@ -class Solution { -public: - int maxProfit(vector& prices) { - int max=0, begin=0, end=0; - bool up=false, down=false; - for (int i=1; i prices[i-1] && up==false){ // goes up - begin = i-1; - up = true; - down = false; - } - if (prices[i] < prices[i-1] && down==false) { // goes down - end = i-1; - down = true; - up = false; - max += (prices[end] - prices[begin]); - } - } - // edge case - if (begin < prices.size() && up==true){ - end = prices.size() - 1; - max += (prices[end] - prices[begin]); - } - return max; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/169-majority-element.h b/Problems/LeetcodeProblems/169-majority-element.h deleted file mode 100644 index 899de429b6742c5d9c09423c9a757057debcbff5..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/169-majority-element.h +++ /dev/null @@ -1,26 +0,0 @@ -#include -class Solution { -public: - int majorityElement(vector& nums) { - int n = nums.size(); - map m_times; - int moreThanTimes = n / 2; - for (auto i = 0; i < n; ++i) { - auto it = m_times.find(nums[i]); - if (it == m_times.end()) { - // No existence in map, insert - m_times.insert(std::pair(nums[i], 1)); - it = m_times.find(nums[i]); - } - // Is it more than ⌊ n/2 ⌋ times ? - if ((*it).second > moreThanTimes) { - return (*it).first; - } - else { - (*it).second++; - } - } - // Can't find - return -1; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/26-remove-duplicates-from-sorted-array.h b/Problems/LeetcodeProblems/26-remove-duplicates-from-sorted-array.h deleted file mode 100644 index 2ce7bb6bb0c18472d1a73ad3ac7396e6d9a32ef3..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/26-remove-duplicates-from-sorted-array.h +++ /dev/null @@ -1,14 +0,0 @@ -class Solution { -public: - int removeDuplicates(vector& nums) { - int n = nums.size(), pos = 0; - if(n <= 1) - return n; - for(int i = 0; i < n-1; ++i) { - if(nums[i] != nums[i+1]) { - nums[++pos] = nums[i+1]; - } - } - return pos+1; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/283-move-zeroes.h b/Problems/LeetcodeProblems/283-move-zeroes.h deleted file mode 100644 index 19059f168609434d3a4d7ca6bf14b5ac64dd1f4c..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/283-move-zeroes.h +++ /dev/null @@ -1,12 +0,0 @@ -class Solution { -public: - void moveZeroes(vector& nums) { - int left = 0, right = 0; - for(; left < nums.size() && nums[left] != 0; left++); - for(right = left; right < nums.size(); right++) { - if(nums[right] == 0) continue; - nums[left++] = nums[right]; - } - while(left < nums.size()) nums[left++] = 0; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/4-median-of-two-sorted-arrays.h b/Problems/LeetcodeProblems/4-median-of-two-sorted-arrays.h deleted file mode 100644 index 57fd986865cd3f90d23a8a5a472fe65f8247f912..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/4-median-of-two-sorted-arrays.h +++ /dev/null @@ -1,34 +0,0 @@ -class Solution { -public: - double findMedianSortedArrays(vector& nums1, vector& nums2) { - int len1 = nums1.size(); - int len2 = nums2.size(); - int len = len1 + len2; - if(len & 1) - return findKth(nums1, 0, nums2, 0, len / 2 + 1); - else - return (findKth(nums1, 0, nums2, 0, len / 2) + findKth(nums1, 0, nums2, 0, len / 2 + 1)) / 2; - } - - // find kth number of two sorted array - double findKth(vector& nums1, int i1, vector& nums2, int i2, int k) { - if (i1 >= nums1.size()) { - return nums2[i2 + k - 1]; - } - if (i2 >= nums2.size()) { - return nums1[i1 + k - 1]; - } - if (k == 1) { - return min(nums1[i1], nums2[i2]); - } - int key1 = i1 + k / 2 - 1 >= nums1.size() ? INT_MAX : nums1[i1 + k / 2 - 1]; - int key2 = i2 + k / 2 - 1 >= nums2.size() ? INT_MAX : nums2[i2 + k / 2 - 1]; - if (key1& nums) { - int max = MIN_INT, temp = 0; - for(auto i = 0; i < nums.size(); ++i) { - temp += nums[i]; - if(temp > max) max = temp; - if(temp < 0) temp = 0; - } - return max; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/66-plus-one.h b/Problems/LeetcodeProblems/66-plus-one.h deleted file mode 100644 index 4aee3156a6859e77280bf4cc4ce6ef75edb3be0b..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/66-plus-one.h +++ /dev/null @@ -1,15 +0,0 @@ -class Solution { -public: - vector plusOne(vector& digits) { - int carry = 1; - for(int i = digits.size() - 1; i >= 0; --i) { - int add = digits[i] + carry; - digits[i] = add % 10; - carry = add / 10; - } - if(carry > 0) { - digits.insert(digits.begin(), carry); - } - return digits; - } -}; \ No newline at end of file diff --git a/Problems/LeetcodeProblems/88-merge-sorted-array.h b/Problems/LeetcodeProblems/88-merge-sorted-array.h deleted file mode 100644 index 19e222e44402add6a3cceb6dd44fe5bfd64a8e45..0000000000000000000000000000000000000000 --- a/Problems/LeetcodeProblems/88-merge-sorted-array.h +++ /dev/null @@ -1,20 +0,0 @@ -class Solution { -public: - void merge(vector& nums1, int m, vector& nums2, int n) { - int i1 = m - 1, i2 = n - 1; - for(int i = m + n - 1; i >= 0; i--) { - if(i1 >= 0 && i2 < 0) - break; - if(i1 < 0 && i2 >= 0) { - nums1[i] = nums2[i2--]; - } - if(i1 >= 0 && i2 >= 0) { - if(nums1[i1] > nums2[i2]) { - nums1[i] = nums1[i1--]; - } else { - nums1[i] = nums2[i2--]; - } - } - } - } -}; \ No newline at end of file