Skip to content

Instantly share code, notes, and snippets.

View EfrainReyes's full-sized avatar

Efrain Reyes EfrainReyes

View GitHub Profile
@EfrainReyes
EfrainReyes / find_median_from_data_stream.py
Created November 12, 2022 16:53
295. Find Median from Data Stream
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)
@EfrainReyes
EfrainReyes / remove_duplicates_from_sorted_array.cs
Created November 11, 2022 01:17
26. Remove Duplicates from Sorted Array (C#)
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];
@EfrainReyes
EfrainReyes / remove_duplicates_from_sorted_array.py
Last active November 11, 2022 01:17
26. Remove Duplicates from Sorted Array (Python)
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
@EfrainReyes
EfrainReyes / remove_all_adjacent_duplicates_in_string.py
Created November 10, 2022 01:05
1047. Remove All Adjacent Duplicates In String
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)
@EfrainReyes
EfrainReyes / nested_list_weight_sum.py
Created November 9, 2022 02:36
339. Nested List Weight Sum
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)
@EfrainReyes
EfrainReyes / online_stock_span.py
Created November 9, 2022 01:02
901. Online Stock Span
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]
@EfrainReyes
EfrainReyes / make_the_string_great.py
Last active November 8, 2022 04:28
1544. Make The String Great
class Solution:
def makeGood(self, s: str) -> str:
if len(s) <= 1:
return s
stack = []
for char in s:
if (stack and stack[-1] != char
and stack[-1].lower() == char.lower()):
@EfrainReyes
EfrainReyes / .gitconfig
Last active March 29, 2017 23:54
my global git config
#[user]
# name = Your Name
# email = youremail@example.com
[core]
autocrlf = true
excludesfile = C:\\Users\\Efrain\\Documents\\gitignore_global.txt
editor = 'C:/Program Files/Sublime Text 3/subl.exe' -n -w
ignorecase = false
[push]
default = simple
@EfrainReyes
EfrainReyes / CustomerModel.cs
Last active August 29, 2015 14:11
Using INotifyPropertyChanged without having to pass the property name or an expression. Running Example: https://dotnetfiddle.net/4P0dhM
public class CustomerModel : ModelBase {
private string _customerName;
public string CustomerName {
get { return _customerName; }
set { SetProperty(ref _customerName, value); }
}
private int _orderCount;
public int OrderCount {
get { return _orderCount; }
@EfrainReyes
EfrainReyes / FizzBuzz.cs
Created November 28, 2014 13:42
Fizz Buzz using functional C#
Enumerable.Range(1, 30).Select(num =>
((Func<string[], string>)
(buzz => new string[]{
buzz[((num + 2) % 3) / 2] +
buzz[((num + 4) % 5) / 4 * 2],
""+num
}.First(r => r != "")))(new[] { null, "fizz", "buzz"})
).ToList().ForEach(s => Console.WriteLine(s));