diff --git a/Leetcode/FindMinimumInRotatedSortedArray.cpp b/Leetcode/FindMinimumInRotatedSortedArray.cpp new file mode 100644 index 0000000..e879759 --- /dev/null +++ b/Leetcode/FindMinimumInRotatedSortedArray.cpp @@ -0,0 +1,27 @@ + + +//Problem Link :https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ + +class Solution { +public: + int findMin(vector& nums) { + int start=0,end=nums.size()-1; + int minValue=INT_MAX; + while(start<=end) + { + int mid=(start+end)/2; + if(nums[mid]>=nums[start]) + { + minValue=min(minValue,nums[start]); + start=mid+1; + } + else + { + minValue=min(minValue,nums[mid]); + end=mid; + } + + } + return minValue; + } +}; \ No newline at end of file diff --git a/Leetcode/HouseRobber.cpp b/Leetcode/HouseRobber.cpp new file mode 100644 index 0000000..c45033b --- /dev/null +++ b/Leetcode/HouseRobber.cpp @@ -0,0 +1,22 @@ +//Problem Link: https://leetcode.com/problems/house-robber/ + + + +class Solution { +public: + int rob(vector& nums) { + int n=nums.size()-1; + if(n==0) + { + return nums[0]; + } + int arr[n+10]; + arr[0]=nums[0]; + arr[1]=max(nums[0],nums[1]); + for(int i=2;i<=n;i++) + { + arr[i]=max(nums[i]+arr[i-2],arr[i-1]); + } + return arr[n]; + } +}; diff --git a/Leetcode/JumpGame.cpp b/Leetcode/JumpGame.cpp new file mode 100644 index 0000000..f6c1c8e --- /dev/null +++ b/Leetcode/JumpGame.cpp @@ -0,0 +1,20 @@ +//problem Link: https://leetcode.com/problems/jump-game/ + + + +class Solution { +public: + bool canJump(vector& nums) { + int maxNow=0; + for(int i=0;i=nums.size()-1) return true; + + return false; + } +}; \ No newline at end of file