题目如下: A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 … 'Z' -> 26 Given a non-empty string containin… 阅读全文
分类: 算法
[LeetCode每日一题]10. Regular Expression Matching
题目如下: Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zer… 阅读全文
[LeetCode每日一题]62. Unique Paths
题目如下: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to… 阅读全文
[LeetCode每日一题]5. Longest Palindromic Substring
题目如下: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 5. Longest Palindromic Substring 这道题让我们求给定字符串的最长回文子串。 第一种解法是动态规划。 设状态空间为二维布尔值数… 阅读全文
[LeetCode每日一题]116. Populating Next Right Pointers in Each Node
题目如下: You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct Node { int val; Node *left; No… 阅读全文
[LeetCode每日一题]114. Flatten Binary Tree to Linked List
题目如下: Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 初看这道题觉得… 阅读全文
[LeetCode每日一题]113. Path Sum II
题目如下: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. 给定一棵二叉树和一个整数sum,让我们找出所有从根节点到叶子节点权值之和为sum的路径。 解题思路为,对二叉树进行深度优先搜索(DFS),并记录所走过的路径,到达叶子节点时判… 阅读全文
[LeetCode每日一题]108. Convert Sorted Array to Binary Search Tree
题目如下: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth o… 阅读全文
[LeetCode每日一题]105. Construct Binary Tree from Preorder and Inorder Traversal
题目如下: Given preorder and inorder traversal of a tree, construct the binary tree. eg: preorder = [3,9,20,15,7] inorder = [9,3,15,20,7] return: 3 / \ 9 20 / \ 15 7 已知二叉树的前序遍历序列和中… 阅读全文
[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: eg: 1 / \ 2 2 / \ /… 阅读全文