随笔分类 - 递归
摘要:Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: 1 class Solution { 2 public: 3 vector<int>q; 4 i
阅读全文
摘要:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n. Example: 题意 给定一数n,求1-n所组成的所有可能的BST树的集合 题解
阅读全文
摘要:A message containing letters from A-Z is being encoded to numbers using the following mapping: Given a non-empty string containing only digits, determ
阅读全文
摘要:Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not conta
阅读全文
摘要:The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total num
阅读全文
摘要:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representati
阅读全文
摘要:Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjac
阅读全文
摘要:Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Exampl
阅读全文
摘要:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. Example: 题意 在1到n中取k个数的所有情况 题解 1 class Solution { 2 public: 3
阅读全文
摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.
阅读全文
摘要: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 p
阅读全文
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return the
阅读全文
摘要:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all
阅读全文
摘要:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb
阅读全文
摘要:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the
阅读全文
摘要:Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. The matching should cover the entire
阅读全文
摘要:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh
阅读全文
摘要:描述 有若干种病毒,每种病毒的特征代码都是一个01串。 每个程序也都是一个01串。 问是否存在不被病毒感染(不包含任何病毒的特征代码)的无限长的程序。 输入第一行是整数n,表示有n个病毒接下来n行,每行是一个由 0,1构成的字符串,表示一个病毒特征代码所有的病毒的特征代码总长度不超过30000输出如
阅读全文
摘要:题目描述 任何一个正整数都可以用 22 的幂次方表示。例如 137=2^7+2^3+2^0137=27+23+20 同时约定方次用括号来表示,即 a^bab 可表示为 a(b)a(b) 。 由此可知, 137137 可表示为: 2(7)+2(3)+2(0)2(7)+2(3)+2(0) 进一步: 7=
阅读全文
摘要:描述 动物园的规划和城市规划一样是个令人头疼的大问题。不幸的是,动物园规划师R.V.L.先生高估了小动物们的智商,他设计了一个极其复杂的动物园道路规划方案,如下图所示: 动物园按照下述方法进行扩建:当动物园规模扩大之后,R.V.L.先生设计的解决方案是把与原来动物园结构一样的区域复制或旋转90度之后
阅读全文