自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [Leetcode]Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two node

2015-07-30 20:59:30 535

原创 [Leetcode]Two Sum

Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe

2015-06-24 09:57:16 682

原创 [Leetcode]Populating Next Right Pointers in Each NodeI&II

Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If t

2015-03-18 22:14:51 661

原创 C++实现快速排序QuickSort

快速排序是典型的分治思想算法。每一遍排序都从序列中取一个值,并且使这个值左边的数都小于等于这个值,右边的都大于等于这个值,这样把整个序列分为两部分,再对这两部分分别递归执行上述操作。该方法的基本思想是:1.先从数列中取出一个数作为key。2.分区过程,将比这个数大的数全放到它的右边,小于或等于它的数全放到它的左边。3.再对左右区间重复第二步,直到各区间只有一个数。

2015-03-04 23:34:46 2810

原创 [Leetcode]Sort List

Sort a linked list in O(n log n) time using constant space complexity.链表排序,O(nlgn)的复杂度,应该是归并或者快排,对链表来说归并应该用起来更顺手一些,尤其是对归并的步骤来说,链表这种数据结构真是再合适不过了。这里我用了递归调用来实现归并步骤,效率可能略微低那么一点点,但是代码简洁得不得了哇~~归并排序是分治

2015-03-03 19:19:01 554

原创 [Leetcode]Single Number

Given an array of integers, every element appears twice except for one. Find that single one.最近两个月事情很多,论文开题,家庭变故,都没有时间学习、做题,也没有时间写博客。现在回来再看感觉自己之前很多东西都做的不到位,所以把之前做过的题目也都翻出来做一下,温故知新嘛~现在回忆一下,这是我做的第

2015-03-02 22:18:29 514

原创 [Leetcode]Clone Graph

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each

2014-12-03 10:33:36 797

原创 [Leetcode]Recover Binary Search Tree

Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis

2014-12-01 20:26:37 630

原创 [Leetcode]Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘

2014-11-28 16:27:19 795

原创 [Leetcode]Next Permutation

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2014-11-27 20:50:27 412

原创 [Leetcode]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

2014-11-27 14:28:06 1058

转载 C++多态的实现原理

From http://bbs.fishc.com/home.php?mod=space&uid=9&do=blog&id=1118点击打开链接C++多态的实现原理1. 用virtual关键字申明的函数叫做虚函数,虚函数肯定是类的成员函数。2. 存在虚函数的类都有一个一维的虚函数表叫做虚表。类的对象有一个指向虚表开始的虚指针。虚表是和类对应的,虚表指针是和对象对应的

2014-11-27 11:09:53 469

转载 c++成员函数的重载、覆盖、隐藏区别

From http://bbs.fishc.com/home.php?mod=space&uid=9&do=blog&id=1122点击打开链接成员函数的重载、覆盖(override)与隐藏很容易混淆,C++程序员必须要搞清楚概念,否则错误将防不胜防。重载与覆盖成员函数被重载的特征:(1)相同的范围(在同一个类中);(2)函数名字

2014-11-27 11:04:34 464

原创 [Leetcode]Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is

2014-11-27 10:17:57 481

原创 [Leetcode]Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c

2014-11-27 00:32:16 793

转载 C++静态成员和静态方法

From http://blog.sina.com.cn/s/blog_5f0d72800100swkz.html点击打开链接当将类的某个数据成员声明为static时,该静态数据成员只能被定义一次,而且要被同类的所有对象共享。各个对象都拥有类中每一个普通数据成员的副本,但静态数据成员只有一个实例存在,与定义了多少类对象无关。静态方法就是与该类相关的,是类的一种行为,而不是与该类的实例对

2014-11-26 16:38:46 659

原创 [Leetcode]Permutations && Permutations II

Given a collection of 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 [3,2,1].组合的题目,第一题无重

2014-11-26 10:19:21 652

原创 [Leetcode]Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".这道题最理想的状态时时间复杂度O(a.size()+b.size()),空间复杂度O(0)。这道题中,我用两个引用added和add分别指向被加数和家数,这

2014-11-25 19:08:21 512

原创 Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retu

2014-11-25 16:41:23 421

原创 [Leetcode]Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","

2014-11-24 15:47:21 423

原创 [Leetcode]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

2014-11-21 21:52:16 419

原创 [Leetcode]Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree

2014-11-20 10:44:15 456

原创 Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary

2014-11-19 20:38:30 392

原创 [Leetcode]Path Sum && Path Sum II

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum

2014-11-19 10:40:49 356

原创 [Leetcode]Combination Sum &&Combination Sum II

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb

2014-11-18 23:45:57 382

原创 [Leetcode]3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact

2014-11-18 15:34:14 565 1

原创 [Leetcode]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 each of

2014-11-15 19:51:56 465

原创 [Leetcode]Jump Game && Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i

2014-11-15 00:23:40 395

原创 [Leetcode]Unique Binary Search Trees II

Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1 3

2014-11-07 09:21:09 468

原创 [Leetcode]Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

2014-11-06 10:45:19 607

原创 [Leetcode]Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found

2014-11-05 13:00:29 423

原创 C++ 关联容器map的用法

这篇博客部分内容转发自http://www.cnblogs.com/anywei/archive/2011/10/27/2226830.html

2014-11-04 15:49:53 593

原创 [Leetcode]Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille

2014-11-04 15:11:02 429

原创 [Leetcode]Subsets I&II

Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,

2014-11-04 09:46:05 540

原创 [Leetcode]Find Minimum in Rotated Sorted Array I & II

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 duplicate exists in

2014-11-03 10:16:59 541

原创 [Leetcode]Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va

2014-11-02 15:18:09 393

原创 [Leetcode]Longest Consecutive Sequence

class Solution {public: int longestConsecutive(vector &num) { map m; int result= 0; for (int i = 0; i < num.size();i++){ m[num[i]] = 1; } for (int i = 0; i < num.size(); i++){ int tm

2014-11-02 12:06:36 364

原创 [Leetcode]Flatten Binary Tree to Linked List (三种方法)

Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1

2014-10-30 23:50:46 678

空空如也

空空如也

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

TA关注的人

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