From 9d01fe37626c40b8afdf416ebdeb0c69aa9b2a5b Mon Sep 17 00:00:00 2001 From: sneha-tambade Date: Mon, 2 Mar 2026 17:40:38 -0800 Subject: [PATCH] Problems solved --- BuySellStockII.cs | 13 +++++++++++++ PeekingIterator.cs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 BuySellStockII.cs create mode 100644 PeekingIterator.cs 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