LEETCODE ALGORITHM:221. Maximal Square
题目
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.
Example:
1 | Input: |
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.
Example:
1 | Input: |
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node's descendants. The tree s could also be considered as a subtree of itself.
Example 1: Given tree s:
1 | 3 |
Given tree t:
In a country popular for train travel, you have planned some train
travelling one year in advance. The days of the year that you will
travel is given as an array days
. Each day is an integer
from 1
to 365
.
Train tickets are sold in 3 different ways:
costs[0]
dollars;costs[1]
dollars;costs[2]
dollars.The passes allow that many days of consecutive travel. For example, if we get a 7-day pass on day 2, then we can travel for 7 days: day 2, 3, 4, 5, 6, 7, and 8.
Implement a MyQueue class which implements a queue using two stacks.
Example:
1 | MyQueue queue = new MyQueue(); |
Notes:
You have a list of words
and a pattern
, and
you want to know which words in words
matches the
pattern.
A word matches the pattern if there exists a permutation of letters
p
so that after replacing every letter x
in
the pattern with p(x)
, we get the desired word.
(Recall that a permutation of letters is a bijection from letters to letters: every letter maps to another letter, and no two letters map to the same letter.)
Return a list of the words in words
that match the given
pattern.
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
Example 1:
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Your goal is to reach the last index in the minimum number of jumps.
Example:
Given an integer matrix, find the length of the longest increasing path.
From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).
Example 1:
1 | Input: nums = |
Given the root
of a binary tree with N
nodes, each node
in the tree has node.val
coins, and there are N
coins total.
In one move, we may choose two adjacent nodes and move one coin from one node to another. (The move may be from parent to child, or from child to parent.)
Return the number of moves required to make every node have exactly one coin.
Example 1: