自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [Leetcode]232. Implement Queue using Stacks

Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(

2016-06-30 09:39:22 199

原创 [Leetcode]225. Implement Stack using Queues

Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet

2016-06-30 09:18:27 255

原创 [Leetcode]155. Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get

2016-06-29 20:55:42 246

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

2016-06-29 20:28:07 200

原创 [Leetcode]61. 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./** * Definition for singly-link

2016-06-29 17:53:22 583

原创 [Leetcode]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-06-29 17:11:30 249

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

2016-06-29 16:25:24 228

原创 [Leetcode]142. Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?设置

2016-06-29 15:33:36 200

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

2016-06-28 22:03:35 232

原创 [Leetcode]234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?/** * Definition for singly-linked list. * struct ListNode { * int va

2016-06-28 20:10:17 201

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

2016-06-27 15:46:17 237

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

2016-06-27 11:35:06 214

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

2016-06-27 10:52:33 173

原创 [Leetcode]203. Remove Linked List Elements

Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** * Definition for si

2016-06-27 09:45:49 250

原创 [Leetcode]141. 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?这个题比较简单,可以设置两根指针,一个每次移动一格,一个移动两格,若发生两根指针指向同一个节点的情况,则说明链表含有环。/** * Definition fo

2016-06-27 09:26:14 190

原创 [Leetcode]83. 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./** * Definition for s

2016-06-27 09:09:48 228

原创 [Leetcode]206. Reverse Linked List

Reverse a singly linked list./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solu

2016-06-27 08:36:19 196

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

2016-06-26 18:37:48 237

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

2016-06-26 18:15:42 184

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

2016-06-26 17:36:12 181

原创 [Leetcode]6. ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I

2016-06-24 14:15:12 227

原创 [Leetcode]3. Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "

2016-06-24 11:22:48 177

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

2016-06-24 10:18:25 206

原创 [Leetcode]1. Two Sum

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:Given nums

2016-06-24 09:35:46 188

原创 Cocos2d-x3.x安装指南

最近趁着做毕设实验的空闲期,看了下cocos2d-x.3x开发,准备写一系列的博客,记录下自己的学习历程。首先要安装代码编译开发环境,这里我使用的是VS2013。安装完了VS2013之后需要下载cocos2d-x,这里有很多版本,不同版本之间差异还是挺大的,有时候代码在这个版本上可以运行,别的版本上却不能运行,我使用的是3.0版本。Cocos2d-x不需要安装,下载后得到一个zip压缩文件,解

2016-06-22 16:22:20 2857

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

2016-06-07 10:57:30 209

原创 [Leetcode]27. Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.

2016-06-07 10:54:50 133

原创 [leetcode]50. Pow(x, n)

Implement pow(x, n).将x的乘积(ret)每次翻番同时将计数(cnt)翻倍,cnt的二倍超出n时,重新计算pow(x, n-cnt),这样ret * pow(x, n-cnt)即是最终的结果。n为负数时用1除以相反数的计算结果即可。测试用例中n的测试数据有INT_MIN,这里直接包了一层函数用long long表示,不然要判断是否是INT_MIN进行特殊处理。cl

2016-06-06 23:03:48 267

原创 [Leetcode]69. Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x.class Solution {public: int mySqrt(int x) { long long left, right, mid; left = 0; right = x;

2016-06-06 22:52:07 200

原创 [Leetcode]70. 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?其实这是一个斐波那契数列,如果用递归方式来解决,时间会超

2016-06-06 22:49:29 181

原创 [Leetcode]171. Excel Sheet Column Number

Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...

2016-06-06 22:45:00 189

原创 [Leetcode]172. Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.我们对n!分解质因子,n!=2^x+3^y+5^z+...,结尾的0一定是1个2和1个5相乘得到的。很显然,这里因子5的个数小于因子2的

2016-06-06 22:41:43 196

原创 [leetcode]202. Happy Number

Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares

2016-06-06 22:31:04 193

原创 [Leetcode]217. Contains Duplicate

Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is

2016-06-06 22:28:06 164

原创 [Leetcode]231. Power of Two

Given an integer, write a function to determine if it is a power of two.麻烦一点的话,用循环来判断。class Solution {public: bool isPowerOfTwo(int n) { if(n<=0) return false; while

2016-06-06 22:22:24 184

原创 [Leetcode]242. Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass

2016-06-06 22:15:43 206

原创 [Leetcode]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-06-06 22:09:21 201

原创 [Leetcode]263. Ugly Number

Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc

2016-06-06 22:05:35 297

原创 [leetcode]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-06-06 22:01:23 224

原创 [Leetcode]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-06-06 21:53:43 554

空空如也

空空如也

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

TA关注的人

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