Skip to content

Instantly share code, notes, and snippets.

View munguial's full-sized avatar

Alberto Munguia munguial

View GitHub Profile
@munguial
munguial / Solution.py
Created April 28, 2020 05:44
Day 27 - Maximal Square
# https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/531/week-4/3312/
class Solution:
def maximalSquare(self, matrix: List[List[str]]) -> int:
dp = {}
self.maxSquare = 0
for row in range(len(matrix)):
for col in range(len(matrix[0])):
self.dfs(matrix, dp, row, col)
return self.maxSquare * self.maxSquare
@munguial
munguial / Solution.kt
Created April 29, 2020 03:53
Day 28 - First Unique Number
// https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/531/week-4/3313/
class FirstUnique(nums: IntArray) {
var m: HashMap<Int, Node?>
var head: Node
var tail: Node
init {
this.m = HashMap<Int, Node?>()
this?.head = Node(-1)
@munguial
munguial / Solution.py
Created April 30, 2020 02:16
Day 29 - Binary Tree Maximum Path Sum
# https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/532/week-5/3314/
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Result:
def __init__(self, subtree, path):
@munguial
munguial / Solution.py
Created May 1, 2020 02:37
Day 30 - Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree
# https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/532/week-5/3315/
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isValidSequence(self, root: TreeNode, arr: List[int]) -> bool:
@munguial
munguial / Solution.py
Created May 2, 2020 05:14
Day 1 - First Bad Version
# https://leetcode.com/explore/challenge/card/may-leetcoding-challenge/534/week-1-may-1st-may-7th/3316/
# The isBadVersion API is already defined for you.
# @param version, an integer
# @return a bool
# def isBadVersion(version):
class Solution:
def firstBadVersion(self, n):
return self.bs(1, n)
@munguial
munguial / Solution.kt
Created May 3, 2020 23:12
Day 3 - Ransom Note
class Solution {
fun canConstruct(ransomNote: String, magazine: String): Boolean {
var m = HashMap<Char, Int>()
magazine.forEach {
if (m.containsKey(it)) {
m[it] = m[it]!!.plus(1)
} else {
m[it] = 1
}
@munguial
munguial / Solution.py
Created May 5, 2020 01:41
Day 2 - Jewels and Stones
class Solution:
def numJewelsInStones(self, J: str, S: str) -> int:
m = {}
for c in J:
m[c] = None
counter = 0
for c in S:
@munguial
munguial / Solution.kt
Created May 5, 2020 15:45
Day 4 - Number Complement
class Solution {
fun findComplement(num: Int): Int {
var n = num
var res = 0
var i = 0
while (n > 0) {
var curr = (n xor 1) and 1
res = res or (curr shl i)
n = n shr 1
i += 1
@munguial
munguial / Solution.py
Created May 6, 2020 03:26
Day 5 - First Unique Character in a String
class Solution:
def firstUniqChar(self, s: str) -> int:
m = {}
for i in range(len(s)):
if s[i] in m:
m[s[i]] = -1
else:
m[s[i]] = i
unique = dict(filter(lambda x: x[1] >= 0, m.items()))
@munguial
munguial / Solution.kt
Created May 7, 2020 05:34
Day 6 - Majority Element
class Solution {
fun majorityElement(nums: IntArray): Int {
var count = 0
var winner = 0
nums.forEach {
if (count == 0) {
winner = it
count = 1
} else if (winner == it) {