Tag: leetcode

Leetcode 159 Longest Substring with At Most Two Distinct Characters G家OA原题

Leetcode 159 Longest Substring with At Most Two Distinct Characters G家OA原题

Given a string s , find the length of the longest substring t that contains at most 2 distinct characters. Example 1: Input: “eceba” Output: 3 Explanation: t is “ece” which its length is 3. Example 2: Input: “ccaabbb” Output: 5 Explanation: t is “aabbb” 

Leetcode 543 Diameter of Binary Tree

Leetcode 543 Diameter of Binary Tree

Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the 

Leetcode 76 Minimum Window Substring 最小窗口子串

Leetcode 76 Minimum Window Substring 最小窗口子串

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). Example: Input: S = “ADOBECODEBANC”, T = “ABC” Output: “BANC” Note: If there is no such window in S that 

Leetcode 261. Graph Valid Tree 无向图成环问题

Leetcode 261. Graph Valid Tree 无向图成环问题

题目大意 Given n nodes labeled from 0 to n-1 and a list of undirected edges (each edge is a pair of nodes), write a function to check whether these edges make up a valid tree. Example 1: Input: n = 5, and edges = [[0,1], 

Leetcode 101. Symmetric Tree 化用深度搜索

Leetcode 101. Symmetric Tree 化用深度搜索

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following [1,2,2,null,3,null,3] is not: 1 

Leetcode 279. Perfect Squares 经典一维动态规划问题

Leetcode 279. Perfect Squares 经典一维动态规划问题

题目表述 Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n. Example 1: Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4. Example 2: Input: n 

Leetcode 102. Binary Tree Level Order Traversal 基本层次遍历

Leetcode 102. Binary Tree Level Order Traversal 基本层次遍历

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its level order traversal as: [ [3], [9,20], 

Leetcode 286. Walls and Gates 联通类型问题

Leetcode 286. Walls and Gates 联通类型问题

题目表述 You are given a m x n 2D grid initialized with these three possible values. -1 – A wall or an obstacle. 0 – A gate. INF – Infinity means an empty room. We use the value 231 – 1 = 2147483647 to represent