This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def numJewelsInStones(self, J: str, S: str) -> int: | |
m = {} | |
for c in J: | |
m[c] = None | |
counter = 0 | |
for c in S: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |