diff --git a/BuySellStock2.java b/BuySellStock2.java new file mode 100644 index 0000000..56ff8da --- /dev/null +++ b/BuySellStock2.java @@ -0,0 +1,16 @@ +/** + * Time Complexity: O(n) where n is the length of prices + * Space Complexity: O(1) + */ +class Solution { + public int maxProfit(int[] prices) { + int result = 0; + for(int i=0; i prices[i]){ + result += prices[i+1] - prices[i]; + } + } + return result; + + } +} \ No newline at end of file