自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

一搏

一切都是最好的安排

  • 博客(21)
  • 问答 (1)
  • 收藏
  • 关注

原创 206. Reverse Linked List

Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?思路1自己想的,结果是超时,为什么会超时 >_<class Solution {public: ListNode* reverse

2016-05-09 23:09:19 267

原创 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.思路先求出尾节点以及链表大小,然后重新连接,感觉链表的链接还是很直观的。clas

2016-05-09 22:46:50 239

原创 189. Rotate Array

Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note: Try to come up as many solutions as you can, ther

2016-05-09 15:16:25 258

原创 229. Majority Element II

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.Hint: How many majority elements could it possibly ha

2016-05-09 14:26:03 246

原创 169. Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element always

2016-05-08 21:00:06 247

原创 快速排序算法

http://blog.csdn.net/morewindows/article/details/6684558整体思路 先把一个数组的第一个数作为基准 从数组尾向前找比基准小的数,找到后换位, 然后从数组头向后找比基准大的数,找到然后换位 最后的情况就是中间是基准,左边都是比它小的数,右边都是比它大的数然后再进行 分治法用作者的一句话就是 挖坑填数+分治法//快速排序void quic

2016-05-08 15:17:04 248

原创 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-05-05 10:53:39 214

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

2016-05-04 22:31:24 180

原创 242. Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s. 看一个数是不是另一个数的anagram anagram :组成元素相同,但顺序不同For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “c

2016-05-04 22:10:20 226

原创 List

相较于 vector 的连续线性空间,List 就显得复杂很多,它的好处是每次插入或删除一个元素,就配置或释放一个元素空间。因此 list 对于空间的运用有绝对的精准。对于任何位置的元素插入或移除,永远是常数时间 list 的节点(node) list 本身和 list 的节点是不同的结构,需要分开设计以下是 STL list 的节点(node)结构//是一个双向链表template<cla

2016-05-04 21:28:40 425

原创 空间配置器allocator

先解决一个坑 allocator在源码剖析的第二章,便是讲的allocator,(第一次看的时候一脸蒙B)因为所有的STL的操作对象都存放在容器内,而容器一定要配置空间以置放资料,都要用到allocatorSGI标准的空间适配器 std::allocator下面的代码,只是把C++的:::operator new 和 ::operator delete 做一层薄薄的包装,SGI 从未使用过它,也

2016-05-04 11:45:35 271

原创 203. Remove Linked List Elements

Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5思路1 为了最后能return修改后的链表,所以我们创建了一个总头dummy,来指向

2016-05-03 22:01:53 202

原创 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 3, t

2016-05-03 21:27:37 217

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

2016-05-03 10:53:02 196

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

2016-05-02 22:59:51 180

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

2016-05-02 21:20:13 315

原创 226. Invert Binary Tree

Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia: This problem was inspired by this original tweet by Max Howell:Google: 90

2016-05-02 15:06:12 286

原创 vector

看完STL源码剖析也有2个月了吧,虽然看的时候明白了,但很快就忘了,Vector更是看过好几次了,但都没有记录下来。还是从开头开始吧,毕竟现在只是打地基,打地基,打地基~.~vector是个动态空间(array是静态空间)所以实现vector关键在于其对大小的控制以及重新配置时的数据移动效率对于扩充空间(不论大多),是“配置新空间/ 数据移动 / 释还旧空间”的大工程,时间成本很高,所以空间配

2016-05-02 13:46:59 508

原创 204. Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.计算比N小的所有质数的个数这道题花了好多时间,数学真实博大精深 ·.·懵懂无知的我最开始是知道暴力求解是行不通的,然后发现第一种解法:把要除的所有比N小的数,变成了sqrt(n),直接少了一半,然后感慨了一番,结果。。。。这尽然是最最基

2016-05-01 23:25:15 353

原创 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 since it in

2016-05-01 11:07:06 331

原创 202. Happy Numbe

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 of i

2016-05-01 09:34:39 356

空空如也

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

TA关注的人

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