Skip to content

Instantly share code, notes, and snippets.

View Lugriz's full-sized avatar
💻
learning

Insomniocode Lugriz

💻
learning
View GitHub Profile
@Lugriz
Lugriz / email-type.ts
Created September 3, 2021 06:05
Defining a type for email using template literal string and conditional types
type Alfa = 'a' | 'b' | 'c' | 'd'
| 'e' | 'f' | 'g' | 'h' | 'i'
| 'j' | 'k' | 'l' | 'm' | 'n'
| 'o' | 'p' | 'q' | 'r' | 's'
| 't' | 'u' | 'v' | 'w' | 'x'
| 'y' | 'z';
type Numeric = '1' | '2' | '3' | '4'
| '5' | '6' | '7' | '8' | '9';
@Lugriz
Lugriz / traversing-bst.ts
Created August 24, 2020 00:37
Atravesando un árbol binario
/**
* 8
* / \
* 6 25
* / \ / \
* 4 8 15 30
* \
* 5
*
*
@Lugriz
Lugriz / binary-search-tree.ts
Created August 16, 2020 19:56
Binary search tree in Typescript
/**
* 8 root = 10 | root = <- deleteNode(10) ->
* / \
* 6 25
* / \ / \
* 4 8 15 30
* \
* 5
*
*/
@Lugriz
Lugriz / Queue.ts
Created July 25, 2020 05:27
Queue implementation
class Node {
public next: Node = null;
constructor(
public value: number
) {}
}
class Queue {
private front: Node = null;
@Lugriz
Lugriz / Stack.ts
Created July 25, 2020 04:57
Stack implementation
class Nodo {
public next: Nodo = null;
constructor(
public value: number
) {}
}
class Stack {
@Lugriz
Lugriz / hashtable.ts
Created July 25, 2020 04:55
Hashtable implementation
/**
* ht.set('myKey2', value);
* |
* v
* hash(key) -> index
* |
* v
* 0| (myKey2, value) -> (myKey, value) -> null,
* 1| ,
* 2| ,
@Lugriz
Lugriz / Insert-Delete-GetRandom-O(1).py
Created February 20, 2020 08:03
Insert Delete GetRandom O(1)
import random
class RandomizedSet:
"""
set = { 1: 0, 2: 1 }
indexes = { 0: 1, 1: 2}
"""
def __init__(self):
@Lugriz
Lugriz / Range-Sum-of-BST.py
Last active February 20, 2020 07:31
Range Sum of BST (Leetcode)
class Solution:
def rangeSumBST(self, root: TreeNode, L: int, R: int) -> int:
_sum = 0
if root:
if root.val >= L and root.val <= R:
_sum += root.val
if root.val <= R:
_sum += self.rangeSumBST(root.right, L, R)
@Lugriz
Lugriz / group-anagrams.java
Last active February 11, 2020 19:07
approach en java
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
if (strs.length == 0) return new ArrayList();
Map<String, List> ans = new HashMap<String, List>();
int[] count = new int[26];
for (String s : strs) {
Arrays.fill(count, 0);
for (char c : s.toCharArray()) count[c - 'a']++;
StringBuilder sb = new StringBuilder("");
@Lugriz
Lugriz / group-anagrams.py
Created February 10, 2020 21:27
group-anagrams
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
result = []
groups = {}
for word in strs:
wordFrecuency = self.__getDictFrecuency(word) # O(n) -> {...}
groupIndex = self.__belongsToAGroup(groups, wordFrecuency) # O(groups.length + wordFrecuency.length)
if groupIndex > -1: