This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StockSpanner: | |
def __init__(self): | |
self.span_stack = [] | |
def next(self, price: int) -> int: | |
span = 1 | |
while self.span_stack and price >= self.span_stack[-1][0]: | |
span += self.span_stack.pop()[1] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def depthSum(self, nestedList: List[NestedInteger]) -> int: | |
def depth_sum_recursive(current_item, depth): | |
if current_item.isInteger(): | |
return current_item.getInteger() * depth | |
return sum(depth_sum_recursive(item, depth + 1) for item in current_item.getList()) | |
return sum(depth_sum_recursive(item, 1) for item in nestedList) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def removeDuplicates(self, s: str) -> str: | |
stack = [] | |
for char in s: | |
if stack and stack[-1] == char: | |
stack.pop() | |
else: | |
stack.append(char) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def removeDuplicates(self, nums: List[int]) -> int: | |
if len(nums) == 1: | |
return 1 | |
non_dupes_ptr = 1 | |
for num in nums: | |
if nums[non_dupes_ptr - 1] < num: | |
nums[non_dupes_ptr] = num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int RemoveDuplicates(int[] nums) { | |
if (nums.Length == 0) | |
return 0; | |
var currentModifiableIndex = 1; | |
var lastModifiedValue = nums[0]; | |
for (var i = 0; i < nums.Length; i++) { | |
var currentValue = nums[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MedianFinder: | |
def __init__(self): | |
self.data = [] | |
def addNum(self, num: int) -> None: | |
bisect.insort(self.data, num) | |
def findMedian(self) -> float: | |
data_length = len(self.data) |
OlderNewer