diff --git a/BuySellStockII.cs b/BuySellStockII.cs new file mode 100644 index 0000000..8103d59 --- /dev/null +++ b/BuySellStockII.cs @@ -0,0 +1,13 @@ +public class Solution { + public int MaxProfit(int[] prices) { + int profit = 0; + for(int i=1;i prices[i-1]) + { + profit += prices[i]-prices[i-1]; + } + } + return profit; + } +} \ No newline at end of file diff --git a/PeekingIterator.cs b/PeekingIterator.cs new file mode 100644 index 0000000..57b6584 --- /dev/null +++ b/PeekingIterator.cs @@ -0,0 +1,33 @@ +using System.Collections.Generic; + +public class PeekingIterator +{ + private IEnumerator _iterator; + private bool _hasNext; + private int _next; + + public PeekingIterator(IEnumerator 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; + } +} \ No newline at end of file