Category: Array
-
121. Best Time to Buy and Sell Stock
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ C# We set a guard clause to catch arrays of length 1 or less. Initialize the first price to be the lowest price. Loop through the array, updating the lowest price and the highest profit thus far. Return the highest profit.
-
217. Contains Duplicate
https://leetcode.com/problems/contains-duplicate/submissions/ C# Here the HashSet structure provides an easy way to check if a number has already been seen. A HashSet can not contain two identical elements and has a lookup time of O(1).
-
1. Two Sum
https://leetcode.com/problems/two-sum/ C# Explanation: Create a dictionary that holds the number as key, and index as value. Loop through the num array and look for the complement in the dictionary. If it’s there, return an array with the current index and the index of the complement found in the dictionary. If it’s not there, add to…