11. Container With Most Water Total Accepted: 99353 Total Submissions: 277586 Difficulty: Medium Contributors: Admin Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, …
Author Archives: czxttkl
Leetcode 125: Valid Palindrome
125. Valid Palindrome Total Accepted: 124387 Total Submissions: 499823 Difficulty: Easy Contributors: Admin Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome. Note:Have you consider that the string might be empty? …
Leetcode 131: Palindrome Partitioning
131. Palindrome Partitioning Total Accepted: 77657 Total Submissions: 260955 Difficulty: Medium Contributors: Admin Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab",Return [ [“aa”,”b”], [“a”,”a”,”b”] ] Code class Solution(object): def partition(self, s): “”” …
Leetcode 118: Pascal’s Triangle
https://leetcode.com/problems/pascals-triangle/ 118. Pascal’s Triangle Total Accepted: 103611 Total Submissions: 290013 Difficulty: Easy Contributors: Admin Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] Code class Solution(object): def generate(self, numRows): “”” :type numRows: int :rtype: List[List[int]] “”” if numRows == 0: return …
Leetcode 120: Triangle
120. Triangle Total Accepted: 84503 Total Submissions: 265352 Difficulty: Medium Contributors: Admin Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to …
Leetcode 116: Populating Next Right Pointers in Each Node
116. Populating Next Right Pointers in Each Node Total Submissions: 287603 Difficulty: Medium Contributors: Admin Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. …
Continue reading “Leetcode 116: Populating Next Right Pointers in Each Node”
Leetcode 222: Count Complete Tree Nodes
222. Count Complete Tree Nodes Total Accepted: 45962 Total Submissions: 173085 Difficulty: Medium Contributors: Admin Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as …
Leetcode 114: Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 Code # Definition for a binary tree node. # class TreeNode(object): # def …
Continue reading “Leetcode 114: Flatten Binary Tree to Linked List”
Leetcode 331: Verify Preorder Serialization of a Binary Tree
331. Verify Preorder Serialization of a Binary Tree Total Accepted: 23475 Total Submissions: 68739 Difficulty: Medium Contributors: Admin One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel value such as …
Continue reading “Leetcode 331: Verify Preorder Serialization of a Binary Tree”
Leetcode 104: Maximum Depth of Binary Tree
104. Maximum Depth of Binary Tree Total Accepted: 184446 Total Submissions: 369369 Difficulty: Easy Contributors: Admin Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Code (BFS) from collections import * # Definition …
Continue reading “Leetcode 104: Maximum Depth of Binary Tree”