- 博客(29)
- 资源 (1)
- 收藏
- 关注
原创 leetcode 100 Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.Subscr
2016-05-30 22:51:23 206
原创 leetcode 098 Validate Binary Search Tree
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 nodes with keys less than the node's key.Th
2016-05-30 21:24:15 281
原创 leetcode 096 Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2016-05-22 15:17:04 216
原创 leetcode 094 Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio
2016-05-22 14:12:05 256
原创 leetcode 092 Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the
2016-05-14 10:50:56 268
原创 leetcode 089 Gray Code
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 number of bits in the code, print the sequence of
2016-05-11 19:43:26 270
原创 leetcode 086 Partition List
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 original relative order of the nodes in e
2016-05-08 14:08:48 209
原创 leetcode 088 Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit
2016-05-08 10:19:12 251
原创 leetcode 083 Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Subscribe to see wh
2016-05-07 23:14:15 295
原创 leetcode 082 Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1
2016-05-07 22:42:51 256
原创 leetcode 081 Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the
2016-05-07 16:48:26 257
原创 leetcode 033 Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur
2016-05-07 16:22:17 213
原创 leetcode 080 Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi
2016-05-07 15:55:26 193
原创 leetcode 079 word search
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 "adjacent" cells are those horizontally or vertically
2016-05-06 23:26:13 757
原创 leetcode 078 subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For
2016-05-06 23:24:30 242
原创 leetcode 077 Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2016-05-03 23:35:31 297
原创 leetcode 075 Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers
2016-05-03 20:09:02 294
原创 leetcode 074 Search a 2D Matrix
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 from left to right.The first integer of each
2016-05-02 20:53:26 237
原创 leetcode 073 Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.class Solution {public: void setZeroes(vector>& matrix) { int rows = matrix.size(), co
2016-05-02 19:27:13 226
原创 leetcode 071 Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"// class Solution {// public:// string simplifyPa
2016-05-02 16:49:41 247
原创 c++ istringstream ostringstream stringstream
int main() { //构造字符串流的时候,空格会成为字符串参数的内部分界,例子中对a,b对象 //的输入"赋值"操作证明了这一点,字符串的空格成为了整型数据与浮点型数据的分界点 //利用分界获取的方法事实上完成了字符串到整型对象与浮点型对象的拆分转换过程 //str()成员函数的使用可以让istringstream对象返回一个string字符串 istringstream ist
2016-05-02 16:37:08 323
原创 leetcode 070 climbing stairs
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 climb to the top?Subscribe to see which c
2016-05-01 22:47:43 223
原创 leetcode 069 Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.Subscribe to see which companies asked this questionclass Solution {public: int mySqrt(int x) { int l =
2016-05-01 22:25:07 228
原创 leetcode 067 Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Subscribe to see which companies asked this questionclass Solution {p
2016-05-01 20:42:18 246
原创 leetcode 066 plus one
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.Subscribe to see
2016-05-01 20:23:31 222
原创 leetcode 064 Minimum Path Sum
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.Note: You can only move either down or right at
2016-05-01 19:57:28 227
原创 leetcode 063 Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the
2016-05-01 17:01:55 566
原创 leetcode 062 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 reach the
2016-05-01 17:00:23 647
原创 leetcode 061 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.Subscribe to see which compan
2016-05-01 15:15:49 274
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人