随笔分类 -  递归

摘要: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 阅读全文
posted @ 2019-02-27 18:22 TobicYAL 阅读(229) 评论(0) 推荐(0)
摘要:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n. Example: 题意 给定一数n,求1-n所组成的所有可能的BST树的集合 题解 阅读全文
posted @ 2019-02-24 22:08 TobicYAL 阅读(203) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-23 19:16 TobicYAL 阅读(176) 评论(0) 推荐(0)
摘要:Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not conta 阅读全文
posted @ 2019-02-23 17:01 TobicYAL 阅读(123) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-23 13:50 TobicYAL 阅读(210) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-23 10:57 TobicYAL 阅读(205) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-15 17:20 TobicYAL 阅读(152) 评论(0) 推荐(0)
摘要:Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. Exampl 阅读全文
posted @ 2019-02-15 16:13 TobicYAL 阅读(137) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-15 15:45 TobicYAL 阅读(123) 评论(0) 推荐(0)
摘要: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. 阅读全文
posted @ 2019-02-11 11:14 TobicYAL 阅读(185) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-09 16:31 TobicYAL 阅读(147) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-08 16:32 TobicYAL 阅读(181) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-02-08 16:25 TobicYAL 阅读(280) 评论(0) 推荐(0)
摘要:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb 阅读全文
posted @ 2019-02-03 22:28 TobicYAL 阅读(238) 评论(0) 推荐(0)
摘要:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the 阅读全文
posted @ 2019-02-03 17:16 TobicYAL 阅读(144) 评论(0) 推荐(0)
摘要:Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. The matching should cover the entire  阅读全文
posted @ 2019-01-25 13:35 TobicYAL 阅读(258) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-01-19 11:44 TobicYAL 阅读(165) 评论(0) 推荐(0)
摘要:描述 有若干种病毒,每种病毒的特征代码都是一个01串。 每个程序也都是一个01串。 问是否存在不被病毒感染(不包含任何病毒的特征代码)的无限长的程序。 输入第一行是整数n,表示有n个病毒接下来n行,每行是一个由 0,1构成的字符串,表示一个病毒特征代码所有的病毒的特征代码总长度不超过30000输出如 阅读全文
posted @ 2018-10-29 23:24 TobicYAL 阅读(1194) 评论(0) 推荐(0)
摘要:题目描述 任何一个正整数都可以用 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= 阅读全文
posted @ 2018-07-29 16:21 TobicYAL 阅读(316) 评论(0) 推荐(0)
摘要:描述 动物园的规划和城市规划一样是个令人头疼的大问题。不幸的是,动物园规划师R.V.L.先生高估了小动物们的智商,他设计了一个极其复杂的动物园道路规划方案,如下图所示: 动物园按照下述方法进行扩建:当动物园规模扩大之后,R.V.L.先生设计的解决方案是把与原来动物园结构一样的区域复制或旋转90度之后 阅读全文
posted @ 2018-06-27 18:58 TobicYAL 阅读(454) 评论(0) 推荐(0)