Skip to content

Instantly share code, notes, and snippets.

View munguial's full-sized avatar

Alberto Munguia munguial

View GitHub Profile
#!/usr/bin/env python3
import sys
numbers = {"zero": 0,
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
public class List {
private Node start, end;
private int size;
public void add(Object variable){
if(start==null){
start = end = new Node(variable);
}
else{
Node temporary = new Node(variable);
@munguial
munguial / Solution.py
Created August 10, 2020 21:25
August - Day 10 - Excel Sheet Column Number
# https://leetcode.com/explore/featured/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3419/
class Solution:
def titleToNumber(self, s: str) -> int:
res = 0
power = 0
for i in reversed(range(len(s))):
res += int(ord(s[i]) - ord('A') + 1) * (26**power)
power += 1
return res
@munguial
munguial / Solution.py
Created August 6, 2020 05:20
August - Day 1 - Detect Capital
class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word.lower() == word:
return True
if word[0].upper() + word[1:].lower() == word:
return True
if word.upper() == word:
return True
@munguial
munguial / Solution.py
Created August 6, 2020 05:15
August - Day 5 - Add and Search Word
class WordDictionary:
def __init__(self):
"""
Initialize your data structure here.
"""
self.root = TrieNode()
def addWord(self, word: str) -> None:
@munguial
munguial / Solution.py
Created August 6, 2020 05:14
August - Day 4 - Power of Four
class Solution:
def isPowerOfFour(self, num: int) -> bool:
i = 0
for i in range(32):
if (1 << i) & num and (1 << i) == num and i % 2 == 0:
return True
return False
@munguial
munguial / Solution.py
Created August 6, 2020 05:13
August - Day 3 - Valid Palindrome
class Solution:
def isPalindrome(self, s: str) -> bool:
def isValid(c: int) -> bool:
if (c >= ord('0') and c <= ord('9')) or \
(c >= ord('A') and c <= ord('Z')) or \
(c >= ord('a') and c <= ord('z')):
return True
return False
def sameChar(i: int, j: int) -> bool:
@munguial
munguial / Solution.java
Created July 31, 2020 23:20
July - Day 31 - Climbing Stairs
// https://leetcode.com/explore/challenge/card/july-leetcoding-challenge/548/week-5-july-29th-july-31st/3407/
import java.util.*;
public class Solution {
TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
public int climbStairs(int n) {
if(n == 0)
@munguial
munguial / Solution.java
Created July 31, 2020 23:18
July - Day 30 - Word Break II
// https://leetcode.com/explore/challenge/card/july-leetcoding-challenge/548/week-5-july-29th-july-31st/3406/
import java.util.*;
class Solution {
public List<String> wordBreak(String s, List<String> dict) {
HashMap<String, ArrayList<String>> dp = new HashMap<String, ArrayList<String>>();
return dfs(s, new HashSet(dict), dp);
}
ArrayList<String> dfs(String s, Set<String> dict, HashMap<String, ArrayList<String>> dp)
@munguial
munguial / Solution.py
Created July 19, 2020 20:35
July - Day 19 - Add Binary
# https://leetcode.com/explore/challenge/card/july-leetcoding-challenge/546/week-3-july-15th-july-21st/3395/
class Solution(object):
def addBinary(self, a: str, b: str) -> str:
return self.add(a, b, len(a) - 1, len(b) - 1, 0)
def add(self, a: str, b: str, i: int, j: int, c: int):
if c == 0 and i < 0 and j < 0:
return ''