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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public int maxProfit(int[] prices) {
int maxProfit = 0;
int bestBuy = prices[0];
for(int i=1;i<prices.length;i++)
{
if(prices[i]>bestBuy)
maxProfit = Math.max(maxProfit,prices[i]-bestBuy);
bestBuy = Math.min(bestBuy,prices[i]);
}
return maxProfit;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions Submission/Ishan Srivastava/Plus One/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution {
public int[] plusOne(int[] digits) {
int carry = 0;
int res[] = new int[digits.length];
digits[digits.length-1] = digits[digits.length-1]+1;
for(int i=digits.length-1;i>-1;i--)
{
int val = digits[i]+carry;
if(val>9)
{
val = val%10;
carry = 1;
}
else
carry = 0;
res[i] = val;
}
if(carry!=0)
{
int res1[] = new int[res.length+1];
for(int i=res.length-1;i>-1;i--)
{
res1[i] = res[i];
}
res1[0] = carry;
return res1;
}
return res;
}
}