自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 328. Odd Even Linked List

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 try to do it in

2016-01-21 00:19:28 417

原创 283. Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you

2016-01-16 18:38:48 366

原创 226. Invert Binary Tree

Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1解答:此为二叉树反转,用递归实现。/** * Definition for a binary tree node. * struc

2016-01-16 18:22:56 328

原创 237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with val

2016-01-16 18:08:15 312

原创 258. Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on

2016-01-16 17:32:53 335

原创 292. Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the

2016-01-16 16:59:02 291

原创 Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked li

2013-11-14 10:17:29 609

原创 Generate Parentheses

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:"((()))", "(()())", "(())()", "()(())", "()()

2013-11-14 09:43:10 616

原创 Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the

2013-11-13 12:13:12 631

原创 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

2013-11-13 11:05:54 583

原创 Container With Most Water

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) and (i, 0). Fin

2013-11-13 09:57:16 633

原创 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.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m

2013-11-12 16:56:02 862

原创 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?思路:从后面往前加

2013-11-12 16:35:41 490

原创 Plus One

Given a number represented as an array of digits, plus one to the number.class Solution {public: vector plusOne(vector &digits) { // IMPORTANT: Please reset any member data you

2013-11-12 16:19:54 506

原创 Rotate Image

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?class Solution {public: void rotate(vector > &

2013-11-12 16:07:09 544

原创 Single Number II

Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi

2013-11-12 15:24:46 528

转载 一个Sqrt函数引发的血案

转自:http://blogread.cn/it/article/3299?f=wb好吧,我承认我标题党了,不过既然你来了,就认真看下去吧,保证你有收获。    我们平时经常会有一些数据运算的操作,需要调用sqrt,exp,abs等函数,那么时候你有没有想过:这个些函数系统是如何实现的?就拿最常用的sqrt函数来说吧,系统怎么来实现这个经常调用的函数呢?    虽然有可能你

2013-11-12 14:21:10 524

原创 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

2013-11-12 12:38:14 581

原创 Permutations

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].思路:用递归。

2013-11-11 12:04:34 533

原创 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

2013-11-11 11:36:49 632

原创 Binary Tree Level Order Traversal

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,9,20,#,#,15,7}, 3 / \ 9 20

2013-11-11 09:58:58 576

原创 Integer to Roman

Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.//主要分开四种情况考虑:0,[1,3],[4,8],9class Solution {public: string intToRoman(in

2013-11-11 09:49:08 592

原创 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

2013-11-11 00:14:54 531

原创 Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},

2013-11-10 22:16:36 548

原创 Swap Nodes in Pairs

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 constant space. Y

2013-11-10 21:56:41 546

原创 Balanced Binary Tree

Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe

2013-11-10 18:21:00 488

原创 Pascal's Triangle

Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class Solution {

2013-11-10 17:54:06 483

原创 Roman to Integer

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.先复习一下罗马数字的表示方法:罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000)。按照下述的规则可以表示

2013-11-10 16:57:40 582

原创 Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:通过二分法,把数组依次分成两段,中点为父节点,左子树为左边小的半部分,右子树为右边大的半部分。/** * Definition for binary tree * struct

2013-11-10 11:18:11 521

原创 Merge Sorted Array

Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of elements initialized in

2013-11-10 10:52:04 558

原创 Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * stru

2013-11-10 10:07:50 530

原创 Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f

2013-11-05 11:17:10 290

原创 Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with

2013-11-05 10:28:55 429

原创 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?思路:当前第n步等于前n-1步走法 + 前n-2步走法,

2013-11-05 10:24:06 405

原创 Search Insert Position

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 duplicates in the array.

2013-11-05 10:15:31 417

原创 Remove Duplicates from Sorted List

Remove Duplicates from Sorted List Total Accepted: 2906 Total Submissions: 8626My SubmissionsGiven a sorted linked list, delete all duplicates such that each element appear only once.F

2013-11-04 20:09:31 496

原创 Populating Next Right Pointers in Each Node

Populating Next Right Pointers in Each Node Total Accepted: 2529 Total Submissions: 7506My SubmissionsGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeL

2013-11-04 18:42:57 425

原创 Remove Element

Remove Element Total Accepted: 2651 Total Submissions: 7854My SubmissionsGiven an array and a value, remove all instances of that value in place and return the new length.The order of

2013-11-04 17:23:27 426

原创 Unique Binary Search Trees

Unique Binary Search Trees Total Accepted: 2405 Total Submissions: 7112My SubmissionsGiven n, how many structurally unique BST's (binary search trees) that store values 1...n?For examp

2013-11-04 16:50:46 420

原创 Linked List Cycle

Linked List Cycle Total Accepted: 2058 Total Submissions: 5552My SubmissionsGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra spac

2013-11-04 11:47:38 365

空空如也

空空如也

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

TA关注的人

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