- 博客(38)
- 资源 (14)
- 收藏
- 关注
原创 Valid Palindrome
描述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, ”A man, a plan, a canal: Panama” is a palindrome. ”race a car” is not
2015-07-29 11:35:28 280
原创 LRU Cache
描述 Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) o
2015-07-29 09:41:02 297
原创 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-07-28 20:29:35 194
原创 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? 中文找到链表换开始的节点: 分析: 两个指针ptr1和ptr2,都从链表头开始走,p
2015-07-28 20:17:28 255
原创 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?分析:判断链表是否有环路最好的方法是时间复杂度O(n),空间复杂度O(1) 的。设置两个指针,一个快一个慢,快 的指针每次走两步, 慢的指针每次走一步, 如果快指针和慢指
2015-07-28 20:06:59 276
原创 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. 中文: 带random随机指向链表任意地方的一个链表 做深
2015-07-28 17:11:11 353
原创 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 i
2015-07-28 14:17:48 280
原创 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
2015-07-28 11:06:12 257
原创 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 linke
2015-07-28 09:59:49 245
原创 Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative. 向右滚动链表k步,k是非负的。 For example: Given 1->2->3->4->5->nullptr and k = 2, return 4->5->1->2->3->nullptr. 分析: 先得到链表的长度。 因
2015-07-27 16:31:50 242
原创 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->
2015-07-27 16:01:04 270
原创 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. 中文:按序排列的单链表,删除冗余元素。分析:只要
2015-07-27 15:48:41 244
原创 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 o
2015-07-27 15:30:08 240
原创 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->nullptr, m = 2 and n = 4, return 1->4->3->2->5->nullptr. Note: Given m, n satisfy th
2015-07-24 10:35:05 253
原创 Add Two Numbers
描述You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a li
2015-07-23 20:17:08 228
原创 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
2015-07-22 11:23:40 283
原创 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 ex
2015-07-21 17:05:09 253
原创 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 one c
2015-07-21 16:54:09 402
原创 Gas Station
描述 There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to i
2015-07-21 15:27:41 248
原创 Set Matrix Zeroes
描述 Given a m n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space? A straight forward solution using O(mn) space is probably a bad i
2015-07-21 14:33:19 315
原创 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
2015-07-21 11:36:41 281
原创 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? 分析 设f(n) 表示爬n 阶楼梯的不同方法数,为了爬到
2015-07-21 11:09:20 237
原创 Plus One
Given a number represented as an array of digits, plus one to the number. 给你一个用数组表示的数,求加一之后的结果,结果还是用数组表示。 分析: 从最后一个数开始加,加完之后放入数组,进位与下一个数相加,如果最后还有进位,则最前面插入这个元素。// 时间复杂度O(n),空间复杂度O(1)class Solution {
2015-07-21 10:58:03 265
原创 Rotate Image
描述 You are given an n n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 分析 首先想到,纯模拟,从外到内一圈一圈的转,但这个方法太慢。 如下图,首先沿着副对角线翻转一次,然后沿着
2015-07-21 10:46:13 200
原创 Trapping Rain Water
描述 Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2015-07-21 10:42:36 232
原创 Valid Sudoku
描述 Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules http://sudoku.com.au/TheRules.aspx . The Sudoku board could be partially filled, where empty cells are filled with the cha
2015-07-21 10:31:42 248
原创 Permutation Sequence
The set [1,2,3,⋯,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): “123” “132” “213” “231” “3
2015-07-10 16:46:38 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 orde
2015-07-10 09:22:35 233
原创 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 in a quadr
2015-07-09 16:39:11 283
原创 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 exa
2015-07-08 20:07:37 270
原创 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) mu
2015-07-08 17:18:15 220
原创 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, wh
2015-07-08 15:30:01 249
原创 Longest Consecutive Sequence
描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is [1, 2, 3
2015-07-08 15:02:46 272
原创 Median of Two Sorted Arrays
描述 There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log(m + n)). 中文: 有两个排序的数组A和B,他们的大小是m和n 找出
2015-07-08 10:56:43 273
原创 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 a
2015-07-02 20:31:20 181
原创 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 return it
2015-07-02 19:58:06 241
原创 Remove Duplicates from Sorted Array II
描述 Follow up for ”Remove Duplicates”: What if duplicates are allowed at most twice? For example, Given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3
2015-07-02 16:34:14 274
cocos2d-x3.0物理引擎源码
2014-05-29
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人