Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions BuyStockSell/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
public int maxProfit(int[] prices) {
int maxi=0;
int mini=prices[0];
for(int i=1;i<prices.length;i++){
int cost=prices[i]-mini;
maxi=Math.max(maxi,cost);
mini=Math.min(prices[i],mini);
}
return maxi;
}
}
13 changes: 13 additions & 0 deletions ContainsDuplicate/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> res=new HashSet<>();
for(int i:nums){
if(res.contains(i)){
return true;
}
res.add(i);
}
return false;

}
}
18 changes: 18 additions & 0 deletions TwoSum/two_sum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int[] twoSum(int[] nums, int target) {
HashMap<Integer,Integer> hashMap=new HashMap<Integer,Integer>();
int []index=new int[2];
for(int i=0;i<nums.length;i++){
int curNum=nums[i];
int match=target-curNum;
if(hashMap.containsKey(match)){
index[0]=i;
index[1]=hashMap.get(match);
}else{
hashMap.put(curNum,i);
}
}
return index;

}
}