随笔分类 -  水题

摘要: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 l 阅读全文
posted @ 2019-03-05 10:41 TobicYAL 阅读(148) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2019-03-04 22:42 TobicYAL 阅读(165) 评论(0) 推荐(0)
摘要: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 symmet 阅读全文
posted @ 2019-03-02 13:34 TobicYAL 阅读(155) 评论(0) 推荐(0)
摘要:Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only 阅读全文
posted @ 2019-03-02 11:26 TobicYAL 阅读(216) 评论(0) 推荐(0)
摘要: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)
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: 1 class Solution { 2 public: 3 void build(TreeNode*root, vector<int>& 阅读全文
posted @ 2019-02-24 21:39 TobicYAL 阅读(125) 评论(0) 推荐(0)
摘要:Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: 1 class Solution { 2 public: 3 ListNode* rev 阅读全文
posted @ 2019-02-24 21:29 TobicYAL 阅读(140) 评论(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)
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the 阅读全文
posted @ 2019-02-23 09:37 TobicYAL 阅读(164) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Example 2: 阅读全文
posted @ 2019-02-21 19:58 TobicYAL 阅读(170) 评论(0) 推荐(0)
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). Y 阅读全文
posted @ 2019-02-19 09:28 TobicYAL 阅读(144) 评论(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)
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f 阅读全文
posted @ 2019-02-13 20:13 TobicYAL 阅读(124) 评论(0) 推荐(0)
摘要:Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path. In a UNIX-style file system, a perio 阅读全文
posted @ 2019-02-13 18:23 TobicYAL 阅读(178) 评论(0) 推荐(0)
摘要:You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you cl 阅读全文
posted @ 2019-02-12 22:11 TobicYAL 阅读(146) 评论(0) 推荐(0)
摘要:Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non-negative integer. Since the return type is an in 阅读全文
posted @ 2019-02-12 22:04 TobicYAL 阅读(300) 评论(0) 推荐(0)
摘要:Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justif 阅读全文
posted @ 2019-02-12 21:46 TobicYAL 阅读(165) 评论(0) 推荐(0)