From ab44bbe8acd16c5e5e9e9b2f43e8178b9dd65bad Mon Sep 17 00:00:00 2001 From: davidmaged171 Date: Fri, 15 Oct 2021 19:04:26 +0200 Subject: [PATCH 1/2] Solved LeetCode Problems --- Leetcode/FindMinimumInRotatedSortedArray.cpp | 27 ++++++++++++++++++++ Leetcode/HouseRobber.cpp | 22 ++++++++++++++++ Leetcode/JumpGame.cpp | 20 +++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 Leetcode/FindMinimumInRotatedSortedArray.cpp create mode 100644 Leetcode/HouseRobber.cpp create mode 100644 Leetcode/JumpGame.cpp 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..d7ed435 --- /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]; + } +}; \ No newline at end of file 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 From 99a030f93dfe7770db83122442503e6765e45e14 Mon Sep 17 00:00:00 2001 From: DavidMaged171 <48919051+DavidMaged171@users.noreply.github.com> Date: Fri, 15 Oct 2021 19:07:47 +0200 Subject: [PATCH 2/2] Update HouseRobber.cpp --- Leetcode/HouseRobber.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Leetcode/HouseRobber.cpp b/Leetcode/HouseRobber.cpp index d7ed435..c45033b 100644 --- a/Leetcode/HouseRobber.cpp +++ b/Leetcode/HouseRobber.cpp @@ -1,4 +1,4 @@ -Problem Link: https://leetcode.com/problems/house-robber/ +//Problem Link: https://leetcode.com/problems/house-robber/ @@ -19,4 +19,4 @@ class Solution { } return arr[n]; } -}; \ No newline at end of file +};