diff --git a/Find min in rotated sorted array/Solution.java b/Find min in rotated sorted array/Solution.java new file mode 100644 index 0000000..14df913 --- /dev/null +++ b/Find min in rotated sorted array/Solution.java @@ -0,0 +1,19 @@ +class Solution { + public int findMin(int[] nums) { + int start = 0; + int end =nums.length-1; + int mid=0; + while(start<=end){ + mid=start+(end-start)/2; + + if(nums[mid]>=nums[end]){ + start=mid+1; + } + else { + end=mid; + } + } + + return nums[mid]; + } +} \ No newline at end of file diff --git a/best-time-to-buy-stock/Solution.java b/best-time-to-buy-stock/Solution.java new file mode 100644 index 0000000..a60e40a --- /dev/null +++ b/best-time-to-buy-stock/Solution.java @@ -0,0 +1,13 @@ +class Solution { + public int maxProfit(int[] prices) { + int max=0; + int minAmount=prices[0]; + + for(int i=1;i hash = new HashSet<>(); + + for(int i =0;i=value){ + value=nums[i]; + max=Math.max(value,max); + continue; + } + } + else{ + value+=nums[i]; + max=Math.max(max,value); + } + + } + + return max; + } +} \ No newline at end of file diff --git a/product of array/Solution.java b/product of array/Solution.java new file mode 100644 index 0000000..f055007 --- /dev/null +++ b/product of array/Solution.java @@ -0,0 +1,23 @@ +class Solution { + public int[] productExceptSelf(int[] nums) { + int[] arr=new int[nums.length]; + int value=1; + int[] prod=new int[nums.length]; + for(int i=0;i0;i--){ + + prod[i]=arr[k]*j; + j=j*nums[i]; + k--; + } + prod[0]=j; + return prod; + } +} \ No newline at end of file diff --git a/sum of integers/Solution.java b/sum of integers/Solution.java new file mode 100644 index 0000000..07a30e7 --- /dev/null +++ b/sum of integers/Solution.java @@ -0,0 +1,19 @@ +class Solution { + public int getSum(int a, int b) { + int carry =(a&b)<<1; + + int sum=a^b; + int total = sum ^ carry; + + System.out.println(total); + + while(carry!=0){ + carry=(sum&carry)<<1; + sum=total; + total^=carry; + + } + + return total; + } +} \ No newline at end of file diff --git a/twosum/Solution.java b/twosum/Solution.java new file mode 100644 index 0000000..2969d8f --- /dev/null +++ b/twosum/Solution.java @@ -0,0 +1,19 @@ +class Solution { + public int[] twoSum(int[] nums, int target) { + int[] arr = new int[2]; + Map hash=new HashMap<>(); + + for(int i=0;i