自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(132)
  • 收藏
  • 关注

原创 [leetcode 289] Game of Life

Quesiton:According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given

2016-04-28 10:08:02 861

原创 [leetcode 77] Combinations

Question: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

2016-04-21 23:33:33 689

原创 [leetcode 199] Binary Tree Right Side View

Question:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binar

2016-04-15 08:35:29 672

原创 [leetcode 240/74] Search a 2D Matrix II -----在左右有序,上下有序中查找数据

Quesiton: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 in ascending from left to rig

2016-04-14 22:08:00 778

原创 memset()函数用法简介

void *memset(void *s, int ch, size_t n);函数解释:将s中前n个字节 (typedef unsigned int size_t )用 ch 替换并返回 s 。memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法。memset是计算机中C/C++语言函数。将s所指向的某一块内存中的前n个 字节

2016-04-14 13:03:00 991

原创 C++访问控制

在c++中有三种访问控制说明符:public 、protected 、private一、访问类中成员情况:private: 只允许类内成员函数和友元函数访问,不允许类的对象访问;protected:只允许类内成员函数、子类内成员函数和友元函数访问,不允许类的对象访问;public: 允许类内成员函数、子类内成员函数、友元函数和类的对象访问。二、继承中的情况:priv

2016-04-12 13:47:25 494

原创 [leetcode 241] Different Ways to Add Parentheses--------计算运算公式字符串中所有可能结果

Question:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *.

2016-03-30 23:26:42 535

原创 [leetcode 173] Binary Search Tree Iterator-------为二叉搜索树实现迭代器功能

Question:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.

2016-03-30 22:23:28 931

原创 C++ STL 中lower_bound() 和 upper_bound()讲解

1、lower_bound()在有序的范围内(具有大于或等于指定值的值)查找第一个元素的位置,该排序标准可由二进制谓词指定。 语法: template ForwardIterator lower_bound( ForwardIterator first, ForwardIterator last, const Type& valu

2016-03-29 23:24:57 13224

原创 [leetcode 300] Longest Increasing Subsequence

Question:Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3

2016-03-29 23:13:27 538

原创 [leetcode 11] Container With Most Water

Question:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai)

2016-03-29 22:20:22 558

原创 [leetcode 48] Rotate Image--------矩阵旋转90度

Quesiton:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?分析:将一个n*n 的矩阵旋转90度,原地旋转,O(1)的空间复

2016-03-23 23:40:26 1123

原创 [leetcode ] Factor Combinations -------------因数组合

Question:Numbers can be regarded as product of its factors. For example,8 = 2 x 2 x 2; = 2 x 4.Write a function that takes an integer n and return all possible combinations of its factors.

2016-03-23 23:07:41 813

原创 [leetcode 75] Sort Colors-----------只有三种颜色的排序

Question: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 us

2016-03-23 22:43:07 916

原创 [leetcode 59] Spiral Matrix II--------数组转圈赋值

Question:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ],

2016-03-23 22:05:34 847

原创 [leetcode 64] Minimum Path Sum------从左上角到右下角的最小路径值

Question: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 d

2016-03-23 08:26:40 2889

原创 [leetcode 24]Swap Nodes in Pairs-----成对翻转链表中的节点

Question:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only co

2016-03-22 21:58:46 387

原创 [leetcode 216] Combination Sum III ------组合数的和(回溯法)

Question:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure

2016-03-22 21:30:13 609

原创 [leetcode 277]Find the Celebrity---------找名人

Question:Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know

2016-03-18 23:02:04 967

原创 [leetcode 244] Shortest Word Distance II------------字典中两个字符串的最短距离

Question:This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameter

2016-03-18 22:32:29 795

原创 [leetcode 46] Permutations------数组中元素的所有排列组合集合

Question:Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [

2016-03-16 23:10:50 547

原创 [leetcode 285] Inorder Successor in BST---查找二叉搜索树中某个节点在中序遍历中的后续节点

Question:Given a binary search tree and a node in it, find the in-order successor of that node in the BST.Note: If the given node has no in-order successor in the tree, return null.分析:

2016-03-16 21:54:43 1580

原创 [leetcode 141] Linked List Cycle----判断链表是否为循环链表

Question:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?分析:判断一个链表是否为循环链表,只要有NULL出现就不是循环链表。方法:设置两个指针,第一个指针从头开始走两步每次,第二个指针每

2016-03-15 22:42:23 735

原创 [leetcode 1] Two Sum

Question:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:

2016-03-15 22:25:43 283

原创 [leetcode 328] Odd Even Linked List

Question:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should

2016-03-15 21:32:24 473

原创 [leetcode 121] Best Time to Buy and Sell Stock---只能买卖股票一次的最大收益

Question:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share o

2016-03-15 08:26:45 1191

原创 [leetcode 89] Gray Code---实现格雷码

Question: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 t

2016-03-14 22:56:30 460

原创 [leetcode 153]Find Minimum in Rotated Sorted Array----求旋转数组的最小值

Question: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).Find the minimum element.You may assume no dupli

2016-03-14 22:31:32 551

原创 [leetcode 62]Unique Paths---机器人向左或向下走到右下角的路径数目

Question: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 tryin

2016-03-14 21:49:11 1253

原创 [leetcode 250]Count Univalue Subtrees ------元素都相同的子树个数

Question:Given a binary tree, count the number of uni-value subtrees.A Uni-value subtree means all nodes of the subtree have the same value.For example:Given binary tree, 5

2016-03-12 17:02:36 3275

原创 [leetcode 298] Binary Tree Longest Consecutive Sequence---求二叉树连续序列的长度

Question:Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of nodes from some starting node to any node in the tree along the pare

2016-03-12 16:01:28 707

原创 [leetcode 22]Generate Parentheses-----n对括号可以组成的括号对序列

Question:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()",

2016-03-11 23:25:39 952

原创 [leetcode 309]Best Time to Buy and Sell Stock with Cooldown--买卖股票with冷却期(DP法)

Question:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you l

2016-03-10 23:02:33 2632

原创 [leetcode 53] Maximum Subarray----最大子数组的和

Question:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarra

2016-03-10 13:05:35 807

原创 [leetcode 286] Walls and Gates---各个点到门的距离

Question:You are given a m x n 2D grid initialized with these three possible values.-1 - A wall or an obstacle.0 - A gate.INF - Infinity means an empty room. We use the value 231 - 1 = 21474

2016-03-09 23:45:42 551

原创 [leetcode 116] Populating Next Right Pointers in Each Node---层序遍历标记每一层的末尾

Question:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its ne

2016-03-09 23:09:12 422

原创 [leetcode 230]Kth Smallest Element in a BST----求二叉搜索树的第K小值

Question:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.分析:题目是

2016-03-09 21:51:39 583

原创 [leetcode 255] Verify Preorder Sequence in Binary Search Tree ---先序遍历验证二叉搜索树

Question:Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.You may assume each number in the sequence is unique.Follow up: C

2016-03-08 23:07:29 1445

原创 [leetcode 108] Convert Sorted Array to Binary Search Tree

Question:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.分析:题目意思是根据给定的一个有序数组,创建一个二叉平衡树。因为数组是从小到大有序的,所以很简单,将数组的中间数作为根节点,这样左右两边的高度差小于等于1,递归操作

2016-03-08 22:02:39 345

原创 [leetcode 35]Search Insert Position

Question:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicate

2016-03-07 23:35:00 283

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除