diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index cdfa6b6a..00000000 Binary files a/.DS_Store and /dev/null differ diff --git a/CPP/.DS_Store b/CPP/.DS_Store deleted file mode 100644 index 27ac926a..00000000 Binary files a/CPP/.DS_Store and /dev/null differ diff --git a/CPP/Problems/.DS_Store b/CPP/Problems/.DS_Store deleted file mode 100644 index c0de1f5d..00000000 Binary files a/CPP/Problems/.DS_Store and /dev/null differ diff --git a/CPP/Problems/Leetcode-102-Binary-Tree-Level-Order-Traversal.cpp b/CPP/Problems/BinaryTreeLevelOrderTraversal.cpp similarity index 92% rename from CPP/Problems/Leetcode-102-Binary-Tree-Level-Order-Traversal.cpp rename to CPP/Problems/BinaryTreeLevelOrderTraversal.cpp index 6a21ccea..1101222c 100644 --- a/CPP/Problems/Leetcode-102-Binary-Tree-Level-Order-Traversal.cpp +++ b/CPP/Problems/BinaryTreeLevelOrderTraversal.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/binary-tree-level-order-traversal/ class Solution { public: vector> levelOrder(TreeNode* root) { diff --git a/CPP/Problems/BitonicArray.cpp b/CPP/Problems/BitonicArray.cpp index 1e3b4b6e..84c920aa 100644 --- a/CPP/Problems/BitonicArray.cpp +++ b/CPP/Problems/BitonicArray.cpp @@ -1,95 +1,95 @@ -// Bitonic array is an array having strictly increasing order upto an element and then having strictly -// decreasing order. It is also called Mountain array. + // Bitonic array is an array having strictly increasing order upto an element and then having strictly + // decreasing order. It is also called Mountain array. -// Program to find element in a bitonic array -// T.C.: O(log n) -// S.C.: O(1) -#include -#include -using namespace std; + // Program to find element in a bitonic array + // T.C.: O(log n) + // S.C.: O(1) + #include + #include + using namespace std; -int findPeakIndex (vector vect, int size) { // find index of peak element - int lo = 0, hi = size-1; - int mid = lo + (hi - lo)/2; + int findPeakIndex (vector vect, int size) { // find index of peak element + int lo = 0, hi = size-1; + int mid = lo + (hi - lo)/2; - while (lo < hi) { - if (mid == size-1 || vect[mid] > vect[mid+1]) { - hi = mid; + while (lo < hi) { + if (mid == size-1 || vect[mid] > vect[mid+1]) { + hi = mid; + } + else if (mid == 0 || vect[mid] > vect[mid-1]) { + lo = mid+1; + } + mid = lo + (hi - lo)/2; } - else if (mid == 0 || vect[mid] > vect[mid-1]) { - lo = mid+1; - } - mid = lo + (hi - lo)/2; + return lo; } - return lo; -} -int leftPart (vector vect, int target, int hi) { // search element in left part - int lo = 0; - int mid = lo + (hi - lo)/2; - while (lo <= hi) { - if (vect[mid] == target) { - return mid; - } - else if (vect[mid] > target) { - hi = mid - 1; + int leftPart (vector vect, int target, int hi) { // search element in left part + int lo = 0; + int mid = lo + (hi - lo)/2; + while (lo <= hi) { + if (vect[mid] == target) { + return mid; + } + else if (vect[mid] > target) { + hi = mid - 1; + } + else { + lo = mid + 1; + } + mid = lo + (hi - lo)/2; } - else { - lo = mid + 1; - } - mid = lo + (hi - lo)/2; + return -1; } - return -1; -} -int rightPart (vector vect, int target, int lo) { // search element in right part - int hi = vect.size()-1; - int mid = lo + (hi - lo)/2; - while (lo <= hi) { - if (vect[mid] == target) { - return mid; - } - else if (vect[mid] < target) { - hi = mid - 1; + int rightPart (vector vect, int target, int lo) { // search element in right part + int hi = vect.size()-1; + int mid = lo + (hi - lo)/2; + while (lo <= hi) { + if (vect[mid] == target) { + return mid; + } + else if (vect[mid] < target) { + hi = mid - 1; + } + else { + lo = mid + 1; + } + mid = lo + (hi - lo)/2; } - else { - lo = mid + 1; - } - mid = lo + (hi - lo)/2; + return -1; } - return -1; -} -int findElement(vector vect, int size, int target) { - // DRIVER CODE - // find peak of array - int peak = findPeakIndex (vect, size); - // compare peak element with target - if (target > vect[peak]) {return -1;} - else if (target == vect[peak]) {return peak;} - // find element in increasing/decreasing sequence - else { - int leftIndex = leftPart(vect, target, peak); - if (leftIndex != -1) { - return leftIndex; - } + int findElement(vector vect, int size, int target) { + // DRIVER CODE + // find peak of array + int peak = findPeakIndex (vect, size); + // compare peak element with target + if (target > vect[peak]) {return -1;} + else if (target == vect[peak]) {return peak;} + // find element in increasing/decreasing sequence else { - return rightPart(vect, target, peak); + int leftIndex = leftPart(vect, target, peak); + if (leftIndex != -1) { + return leftIndex; + } + else { + return rightPart(vect, target, peak); + } } + return 0; } - return 0; -} -int main () { - vector numvect; - int num, target; - cin>>num; - cin>>target; - for (int i = 0; i < num; i++) { - int temp; - cin>>temp; - numvect.push_back(temp); + int main () { + vector numvect; + int num, target; + cin>>num; + cin>>target; + for (int i = 0; i < num; i++) { + int temp; + cin>>temp; + numvect.push_back(temp); + } + cout<& height) { diff --git a/CPP/Problems/Leetcode-740-Delete-And-Earn.cpp b/CPP/Problems/Delete_and_Earn.cpp similarity index 90% rename from CPP/Problems/Leetcode-740-Delete-And-Earn.cpp rename to CPP/Problems/Delete_and_Earn.cpp index e6b523f5..96b1d5c7 100644 --- a/CPP/Problems/Leetcode-740-Delete-And-Earn.cpp +++ b/CPP/Problems/Delete_and_Earn.cpp @@ -1,4 +1,6 @@ +// Question Link // https://leetcode.com/problems/delete-and-earn/ +// ---------------------------------------------- class Solution { public: int deleteAndEarn(vector& nums) { diff --git a/CPP/Problems/Find First and Last Position of Element in Sorted Array.cpp b/CPP/Problems/Find First and Last Position of Element in Sorted Array.cpp new file mode 100644 index 00000000..8d00eff3 --- /dev/null +++ b/CPP/Problems/Find First and Last Position of Element in Sorted Array.cpp @@ -0,0 +1,21 @@ +class Solution { +public: + vector searchRange(vector& nums, int target) { + vectorans; + auto low=lower_bound(nums.begin(),nums.end(),target); + auto upp=upper_bound(nums.begin(),nums.end(),target); + if(low==nums.end()|| *low!=target ) + { + ans.push_back(-1); + ans.push_back(-1); + } + else + { + int start=low-nums.begin(); + int end=upp-nums.begin()-1; + ans.push_back(start); + ans.push_back(end); + } + return ans; + } +}; diff --git a/CPP/Problems/Leetcode-1346-Check-If-N-and-Its-Double-Exist.cpp b/CPP/Problems/Leetcode-1346-Check-If-N-and-Its-Double-Exist.cpp deleted file mode 100644 index de7313bd..00000000 --- a/CPP/Problems/Leetcode-1346-Check-If-N-and-Its-Double-Exist.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// https://leetcode.com/problems/check-if-n-and-its-double-exist/ -class Solution { -public: - bool checkIfExist(vector& arr) { - for (int i = 0; i < arr.size(); i++) { - for (int j = 0; j < arr.size(); j++) { - if (i!=j) { - if (arr[i] == 2*arr[j]) - return true; - } - } - } - return false; - } -}; \ No newline at end of file diff --git a/CPP/Problems/Leetcode-1351-Count-Negative-Numbers-in-a-Sorted-Matrix.cpp b/CPP/Problems/Leetcode-1351-Count-Negative-Numbers-in-a-Sorted-Matrix.cpp deleted file mode 100644 index 4054ec1b..00000000 --- a/CPP/Problems/Leetcode-1351-Count-Negative-Numbers-in-a-Sorted-Matrix.cpp +++ /dev/null @@ -1,17 +0,0 @@ -// https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/ -class Solution { -public: - int countNegatives(vector>& grid) { - int count = 0; - - for (int row = 0; row < grid.size(); row++) { - for (int col = grid[row].size()-1; col >= 0; col--) { - if (grid[row][col] < 0) - count++; - else - break; - } - } - return count; - } -}; \ No newline at end of file diff --git a/CPP/Problems/Leetcode-1572-Matrix-Diagonal-Sum.cpp b/CPP/Problems/Leetcode-1572-Matrix-Diagonal-Sum.cpp deleted file mode 100644 index de887a0d..00000000 --- a/CPP/Problems/Leetcode-1572-Matrix-Diagonal-Sum.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// https://leetcode.com/problems/matrix-diagonal-sum/ -class Solution { -public: - int diagonalSum(vector>& mat) { - int rc = 0; - int TotalSum = 0; - // Primary Diagonal - while (rc < mat.size()) { - TotalSum += mat[rc][rc]; - rc++; - } - // Secondary Diagonal - int r = mat.size()-1, c = 0; - while (r >= 0 && c < mat.size()) { - TotalSum += mat[r][c]; - r--; - c++; - } - if (mat.size() & 1) - return TotalSum - (mat[mat.size()/2][mat.size()/2]); - return TotalSum; - } -}; \ No newline at end of file diff --git a/CPP/Problems/Leetcode-231-Power-of-Two.cpp b/CPP/Problems/Leetcode-231-Power-of-Two.cpp deleted file mode 100644 index 7a074138..00000000 --- a/CPP/Problems/Leetcode-231-Power-of-Two.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// https://leetcode.com/problems/power-of-two/ -class Solution { -public: - bool isPowerOfTwo(int x) { - return x && (!(x&(x-1))); - } -}; \ No newline at end of file diff --git a/CPP/Problems/Leetcode-287-Find-the-Duplicate-Number.cpp b/CPP/Problems/Leetcode-287-Find-the-Duplicate-Number.cpp deleted file mode 100644 index b6b30564..00000000 --- a/CPP/Problems/Leetcode-287-Find-the-Duplicate-Number.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// https://leetcode.com/problems/find-the-duplicate-number/ -class Solution { -public: - int findDuplicate(vector& nums) { - - // first thing that comes to my mind is using the set - with O(N) space - // using two for loop (N^2) - // using another array of same size and updating the value if every times - //element is there - int slow=0; - int fast=0; - - do { - slow=nums[slow]; - fast=nums[nums[fast]]; - - }while (slow !=fast); - - int slow2=0; - - while (slow2!=slow){ - slow2=nums[slow2]; - slow=nums[slow]; - } - - return slow; - - } -}; - diff --git a/CPP/Problems/Leetcode-34-find-first-and-last-position-of-element-in-sorted-array.cpp b/CPP/Problems/Leetcode-34-find-first-and-last-position-of-element-in-sorted-array.cpp index a98ff0cd..6ebcb4e2 100644 --- a/CPP/Problems/Leetcode-34-find-first-and-last-position-of-element-in-sorted-array.cpp +++ b/CPP/Problems/Leetcode-34-find-first-and-last-position-of-element-in-sorted-array.cpp @@ -1,22 +1,36 @@ -// https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ class Solution { public: vector searchRange(vector& nums, int target) { - vectorans; - auto low=lower_bound(nums.begin(),nums.end(),target); - auto upp=upper_bound(nums.begin(),nums.end(),target); - if(low==nums.end()|| *low!=target ) - { - ans.push_back(-1); - ans.push_back(-1); + int n=nums.size(); + int l=0,r=n-1; + int p1=-1,p2=-1; + while(l<=r){ + int mid=l+(r-l)/2; + if(nums[mid]==target){ + p1=mid; + r=mid-1; + } + else if(nums[mid]>target){ + r=mid-1; + } + else + l=mid+1; } - else - { - int start=low-nums.begin(); - int end=upp-nums.begin()-1; - ans.push_back(start); - ans.push_back(end); + l=0,r=n-1; + while(l<=r){ + int mid=l+(r-l)/2; + if(nums[mid]>=target+1){ + r=mid-1; + } + else{ + + l=mid+1; + } + } - return ans; + p2=l; + if(p1!=-1) + return {p1,p2-1}; + return {-1,-1}; } }; diff --git a/CPP/Problems/Leetcode-43-Multiply-Strings.cpp b/CPP/Problems/Leetcode-43-Multiply-Strings.cpp deleted file mode 100644 index 6b572c10..00000000 --- a/CPP/Problems/Leetcode-43-Multiply-Strings.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// https://leetcode.com/problems/multiply-strings/ -class Solution { -public: - string multiply(string num1, string num2) { - int n1 = stoi(num1), n2 = stoi(num2); - return to_string(n1*n2); - } -}; \ No newline at end of file diff --git a/CPP/Problems/Leetcode-7-Reverse-Integer.cpp b/CPP/Problems/Leetcode-7-Reverse-Integer.cpp deleted file mode 100644 index e9dfd061..00000000 --- a/CPP/Problems/Leetcode-7-Reverse-Integer.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// https://leetcode.com/problems/reverse-integer/ -class Solution { -public: - int reverse(int x) { - int reverse =0; - while (x!=0) - { - if(214748364 reverse) - return 0; - reverse= (reverse * 10) + x%10; - x/=10; - } - return reverse; - } -}; diff --git a/CPP/Problems/Leetcode-674-Longest-Continuous-Increasing-Subsequence-Easy.cpp b/CPP/Problems/Longest-Continuous-Increasing-Subsequence-Easy.cpp similarity index 82% rename from CPP/Problems/Leetcode-674-Longest-Continuous-Increasing-Subsequence-Easy.cpp rename to CPP/Problems/Longest-Continuous-Increasing-Subsequence-Easy.cpp index 6676d1eb..755ca9e8 100644 --- a/CPP/Problems/Leetcode-674-Longest-Continuous-Increasing-Subsequence-Easy.cpp +++ b/CPP/Problems/Longest-Continuous-Increasing-Subsequence-Easy.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/longest-continuous-increasing-subsequence/ class Solution { public: int findLengthOfLCIS(vector& nums) { diff --git a/CPP/Problems/Leetcode-152-Maximum-Product-Subarray.cpp b/CPP/Problems/MaximumProductSubarray.cpp similarity index 89% rename from CPP/Problems/Leetcode-152-Maximum-Product-Subarray.cpp rename to CPP/Problems/MaximumProductSubarray.cpp index c3f97ea9..5a5c56a9 100644 --- a/CPP/Problems/Leetcode-152-Maximum-Product-Subarray.cpp +++ b/CPP/Problems/MaximumProductSubarray.cpp @@ -1,4 +1,7 @@ +// Question Link // https://leetcode.com/problems/maximum-product-subarray/ +// ---------------------------------------------- + class Solution { public: int maxProduct(vector& nums) { diff --git a/CPP/Problems/Leetcode-4-Median-of-Two-Sorted-Arrays.cpp b/CPP/Problems/Median of Two Sorted Arrays.cpp similarity index 93% rename from CPP/Problems/Leetcode-4-Median-of-Two-Sorted-Arrays.cpp rename to CPP/Problems/Median of Two Sorted Arrays.cpp index b83e8dcf..fb2772ea 100644 --- a/CPP/Problems/Leetcode-4-Median-of-Two-Sorted-Arrays.cpp +++ b/CPP/Problems/Median of Two Sorted Arrays.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/median-of-two-sorted-arrays/ class Solution { public: double findMedianSortedArrays(vector& nums1, vector& nums2) { diff --git a/CPP/Problems/Leetcode-1155-Number-of-dice-rolls-with-targe-sum.cpp b/CPP/Problems/Number of Dice Rolls With Target Sum.cpp similarity index 90% rename from CPP/Problems/Leetcode-1155-Number-of-dice-rolls-with-targe-sum.cpp rename to CPP/Problems/Number of Dice Rolls With Target Sum.cpp index 45527c8a..fc091137 100644 --- a/CPP/Problems/Leetcode-1155-Number-of-dice-rolls-with-targe-sum.cpp +++ b/CPP/Problems/Number of Dice Rolls With Target Sum.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/ class Solution { public: diff --git a/CPP/Problems/Leetcode-9-Palindrome-Number.cpp b/CPP/Problems/Palindrome Number.cpp similarity index 89% rename from CPP/Problems/Leetcode-9-Palindrome-Number.cpp rename to CPP/Problems/Palindrome Number.cpp index 27605362..6b4ba480 100644 --- a/CPP/Problems/Leetcode-9-Palindrome-Number.cpp +++ b/CPP/Problems/Palindrome Number.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/palindrome-number/ class Solution { public: bool isPalindrome(int x) { diff --git a/CPP/Problems/Reverse Integer.cpp b/CPP/Problems/Reverse Integer.cpp new file mode 100644 index 00000000..f390d5de --- /dev/null +++ b/CPP/Problems/Reverse Integer.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + int reverse(int x) { +int reverse =0; +while (x!=0) +{ +if(214748364 reverse) +return 0; +reverse= (reverse * 10) + x%10; +x/=10; +} +return reverse; +} + + + +}; diff --git a/CPP/Problems/Leetcode-13-Roman-to-Integer.cpp b/CPP/Problems/Roman to Integer.cpp similarity index 90% rename from CPP/Problems/Leetcode-13-Roman-to-Integer.cpp rename to CPP/Problems/Roman to Integer.cpp index d9d179f7..bb2a56ad 100644 --- a/CPP/Problems/Leetcode-13-Roman-to-Integer.cpp +++ b/CPP/Problems/Roman to Integer.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/roman-to-integer/ class Solution { public: int romanToInt(string s) { diff --git a/CPP/Problems/Leetcode-8-String-to-Integer-(atoi).cpp b/CPP/Problems/String to Integer (atoi).cpp similarity index 95% rename from CPP/Problems/Leetcode-8-String-to-Integer-(atoi).cpp rename to CPP/Problems/String to Integer (atoi).cpp index daf1e6a1..53cd345d 100644 --- a/CPP/Problems/Leetcode-8-String-to-Integer-(atoi).cpp +++ b/CPP/Problems/String to Integer (atoi).cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/string-to-integer-atoi/ class Solution { public: int myAtoi(string s) { diff --git a/CPP/Problems/Leetcode-2-Add-Two-Numbers.cpp b/CPP/Problems/add-two-numbers.cpp similarity index 96% rename from CPP/Problems/Leetcode-2-Add-Two-Numbers.cpp rename to CPP/Problems/add-two-numbers.cpp index 80c433a9..af90a79c 100644 --- a/CPP/Problems/Leetcode-2-Add-Two-Numbers.cpp +++ b/CPP/Problems/add-two-numbers.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/add-two-numbers/ /** * Definition for singly-linked list. * struct ListNode { diff --git a/CPP/Problems/Leetcode-2425-Bitwise-XOR-Of-All-Pairings.cpp b/CPP/Problems/biwise_xor_pairing.cpp similarity index 89% rename from CPP/Problems/Leetcode-2425-Bitwise-XOR-Of-All-Pairings.cpp rename to CPP/Problems/biwise_xor_pairing.cpp index 3bcb7b30..c15876e5 100644 --- a/CPP/Problems/Leetcode-2425-Bitwise-XOR-Of-All-Pairings.cpp +++ b/CPP/Problems/biwise_xor_pairing.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/bitwise-xor-of-all-pairings/ class Solution { public: int xorAllNums(vector& nums1, vector& nums2) { diff --git a/CPP/Problems/Leetcode-1232-Check-If-It-Is-A-Straight-Line.cpp b/CPP/Problems/check-if-it-is-a-straight-line.cpp similarity index 100% rename from CPP/Problems/Leetcode-1232-Check-If-It-Is-A-Straight-Line.cpp rename to CPP/Problems/check-if-it-is-a-straight-line.cpp diff --git a/CPP/Problems/findTheDuplicateNumber.cpp b/CPP/Problems/findTheDuplicateNumber.cpp new file mode 100644 index 00000000..e37f2d7c --- /dev/null +++ b/CPP/Problems/findTheDuplicateNumber.cpp @@ -0,0 +1,64 @@ +/* Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. + +There is only one repeated number in nums, return this repeated number. + +You must solve the problem without modifying the array nums and uses only constant extra space. + + + +Example 1: + +Input: nums = [1,3,4,2,2] +Output: 2 +Example 2: + +Input: nums = [3,1,3,4,2] +Output: 3 + + +Constraints: + +1 <= n <= 105 +nums.length == n + 1 +1 <= nums[i] <= n +All the integers in nums appear only once except for precisely one integer which appears two or more times. + + +Follow up: + +How can we prove that at least one duplicate number must exist in nums? +Can you solve the problem in linear runtime complexity? + + + +Solution:*/ + +class Solution { +public: + int findDuplicate(vector& nums) { + + // first thing that comes to my mind is using the set - with O(N) space + // using two for loop (N^2) + // using another array of same size and updating the value if every times + //element is there + int slow=0; + int fast=0; + + do { + slow=nums[slow]; + fast=nums[nums[fast]]; + + }while (slow !=fast); + + int slow2=0; + + while (slow2!=slow){ + slow2=nums[slow2]; + slow=nums[slow]; + } + + return slow; + + } +}; + diff --git a/CPP/Problems/Leetcode-53-Maximum-Subarray.cpp b/CPP/Problems/maximum-subarray.cpp similarity index 100% rename from CPP/Problems/Leetcode-53-Maximum-Subarray.cpp rename to CPP/Problems/maximum-subarray.cpp diff --git a/CPP/Problems/Leetcode-88-Merge-Sorted-Arrays.cpp b/CPP/Problems/merge-sorted-arrays.cpp similarity index 89% rename from CPP/Problems/Leetcode-88-Merge-Sorted-Arrays.cpp rename to CPP/Problems/merge-sorted-arrays.cpp index 1f8b1778..584fb99c 100644 --- a/CPP/Problems/Leetcode-88-Merge-Sorted-Arrays.cpp +++ b/CPP/Problems/merge-sorted-arrays.cpp @@ -1,8 +1,7 @@ -// https://leetcode.com/problems/merge-sorted-array/ class Solution { public: void merge(vector& nums1, int m, vector& nums2, int n) { - int h=m; + int h=m; int j=(m+n)-1; int i=0; int k=0; diff --git a/CPP/Problems/Leetcode-283-Move-Zeroes.cpp b/CPP/Problems/move-zeroes.cpp similarity index 89% rename from CPP/Problems/Leetcode-283-Move-Zeroes.cpp rename to CPP/Problems/move-zeroes.cpp index e4722a2f..68e67964 100644 --- a/CPP/Problems/Leetcode-283-Move-Zeroes.cpp +++ b/CPP/Problems/move-zeroes.cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/move-zeroes/ class Solution { public: void moveZeroes(vector& nums) { diff --git a/CPP/Problems/Leetcode-50-Pow(x,n).cpp b/CPP/Problems/pow(x,n).cpp similarity index 89% rename from CPP/Problems/Leetcode-50-Pow(x,n).cpp rename to CPP/Problems/pow(x,n).cpp index 0b497a84..c844629b 100644 --- a/CPP/Problems/Leetcode-50-Pow(x,n).cpp +++ b/CPP/Problems/pow(x,n).cpp @@ -1,4 +1,3 @@ -// https://leetcode.com/problems/powx-n/ class Solution { public: //binary exponentiation diff --git a/CPP/Problems/queries-on-number-of-points-inside-circle.cpp b/CPP/Problems/queries-on-number-of-points-inside-circle.cpp new file mode 100644 index 00000000..78a3fda4 --- /dev/null +++ b/CPP/Problems/queries-on-number-of-points-inside-circle.cpp @@ -0,0 +1,25 @@ +class Solution { +public: + bool checkStraightLine(vector>& coordinates) { + bool flag=true; + + int x1=coordinates[0][0]; + int y1=coordinates[0][1]; + int x2=coordinates[1][0]; + int y2=coordinates[1][1]; + int m1=y2-y1; + int m2=x2-x1; + int curdx=0; + int curdy=0; + for(int i=2;i twoSum(vector& nums, int target) { diff --git a/CPP/Problems/Leetcode-941-Valid-Mountain-Array.cpp b/CPP/Problems/valid-mountain-array.cpp similarity index 88% rename from CPP/Problems/Leetcode-941-Valid-Mountain-Array.cpp rename to CPP/Problems/valid-mountain-array.cpp index 301f38d6..936c9fb5 100644 --- a/CPP/Problems/Leetcode-941-Valid-Mountain-Array.cpp +++ b/CPP/Problems/valid-mountain-array.cpp @@ -1,4 +1,4 @@ -// https://leetcode.com/problems/valid-mountain-array/ + class Solution { public: bool validMountainArray(vector& A) {