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
13 changes: 13 additions & 0 deletions BuySellStockII.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Solution {
public int MaxProfit(int[] prices) {
int profit = 0;
for(int i=1;i<prices.Length;i++)
{
if(prices[i] > prices[i-1])
{
profit += prices[i]-prices[i-1];
}
}
return profit;
}
}
33 changes: 33 additions & 0 deletions PeekingIterator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;

public class PeekingIterator
{
private IEnumerator<int> _iterator;
private bool _hasNext;
private int _next;

public PeekingIterator(IEnumerator<int> iterator)
{
_iterator = iterator;
_hasNext = true;
}

public int Peek()
{
return _iterator.Current;;
}

public int Next()
{
int result = _iterator.Current;

_hasNext = _iterator.MoveNext();

return result;
}

public bool HasNext()
{
return _hasNext;
}
}