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.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_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_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
using StringHelpers;
using NUnit.Framework;
namespace olakease.Tests {
[TestFixture]
public class SuperTest {
[Test]
public void NullObjectShouldNotThrowException() {
object obj = null;
@EfrainReyes
EfrainReyes / ValidateAjaxAttribute.cs
Last active October 23, 2015 19:28
Use MVC's model state on Ajax forms, provided that there's some client-side code to capture the validation output
/// <summary>
/// http://stackoverflow.com/questions/14005773/use-asp-net-mvc-validation-with-jquery-ajax
/// </summary>
public class ValidateAjaxAttribute : ActionFilterAttribute, IExceptionFilter
{
public override void OnActionExecuting(ActionExecutingContext filterContext) {
if(!filterContext.HttpContext.Request.IsAjaxRequest()) {
return;
}