自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

晨太狼之狼堡

二货一枚快乐多

  • 博客(59)
  • 收藏
  • 关注

原创 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.Your goal is

2015-08-30 15:27:19 201

原创 Jump Game

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 if

2015-08-30 13:17:08 196

原创 Gas Station

There are N gas stations along a circular route, where the amount of gas at stationi is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from stationi to it

2015-08-29 21:12:34 197

原创 Candy

There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on

2015-08-29 18:45:01 196

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

2015-08-28 23:15:26 198

原创 Single Number

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

2015-08-28 22:17:08 195

原创 Max Points on a Line

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.Solution:/** * Definition for a point. * struct Point { * int x; * int y; *

2015-08-28 20:44:35 204

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

2015-08-27 21:00:09 245

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

2015-08-26 16:16:01 195

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

2015-08-25 23:27:16 182

原创 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(mn) s

2015-08-25 22:18:31 434

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

2015-08-25 21:33:37 216

原创 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?Solution:class Solution {public: void rotate(v

2015-08-24 22:42:22 152

原创 Spiral Matrix II

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

2015-08-24 20:50:06 201

原创 Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You

2015-08-24 15:45:02 207

原创 Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Solution:/** * Definition for singly-linked list. * struct ListNode { * int val; *

2015-08-24 00:51:53 234

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

2015-08-23 21:42:07 215

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

2015-08-21 17:50:15 245

原创 Reverse Linked List

Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?Solution:/** * Definition for singly

2015-08-20 23:38:09 246

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

2015-08-20 23:21:27 210

原创 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. You m

2015-08-14 00:42:05 208

原创 Partition List

Given a linked list and a value x, partition it such that all nodes less thanx come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of

2015-08-14 00:27:35 279

原创 Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->

2015-08-13 23:22:29 293

原创 Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.Solution:/** * Defi

2015-08-13 22:24:02 200

原创 Copy List with Random Pointer

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.Solution:/** * Definition f

2015-08-13 13:50:22 396

原创 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.Solution:/** * Definition for

2015-08-13 13:48:36 139

原创 Linked List Cycle II

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

2015-08-10 19:20:15 194

原创 Linked List Cycle

Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Solution:/** * Definition for singly-linked list. * struct ListNode { * i

2015-08-10 13:15:11 182

原创 Reorder List

Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to {1,4

2015-08-09 14:49:56 188

原创 Insertion Sort List

Sort a linked list using insertion sort.Solution:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NUL

2015-08-09 11:47:13 211

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

2015-08-08 21:30:43 207

原创 4Sum

Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements

2015-08-08 20:40:30 192

原创 3Sum

Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c) m

2015-08-07 23:48:15 187

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

2015-08-07 21:45:17 205

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

2015-08-06 22:39:56 192

原创 Remove Duplicates from Sorted Array

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

2015-08-06 21:36:00 197

原创 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 linei is at (i, ai) and (i, 0). Find

2015-08-06 21:21:38 195

原创 First Missing Positive

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant spa

2015-08-05 21:05:11 282

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

2015-08-05 19:48:43 222

原创 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.Solution:/** * Definition for singly-linked list.

2015-08-04 23:33:16 216

空空如也

空空如也

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

TA关注的人

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