自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

搬砖小松鼠的博客

越努力,越幸运!

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

原创 leetcode刷题日记—— 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},

2015-12-31 15:42:16 261

原创 leetcode刷题日记—— 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?问题分析

2015-12-31 12:21:12 277

原创 leetcode刷题日记——Find Minimum in Rotated Sorted Array II

Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unkno

2015-12-30 20:19:54 233

原创 leetcode刷题日记——Find Minimum 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).Find the minimum element.You may assume no duplicate exists in the

2015-12-30 20:05:51 244

原创 leetcode刷题日记—— Count Primes

Description:Count the number of prime numbers less than a non-negative number, n.问题分析:求出比n小的素数的个数。解决代码实现就是判断是否为是素数。实现代码如下:class Solution {public: int countPrimes(int n) { if(n==0) r

2015-12-30 19:39:51 290

原创 leetcode刷题日记—— 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-12-30 18:55:28 241

原创 leetcode刷题日记——Search a 2D Matrix II

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 in ascending from left to right.Integers in ea

2015-12-30 18:44:28 246

原创 leetcode刷题日记——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 r

2015-12-30 17:08:13 247

原创 leetcode刷题日记——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

2015-12-30 16:51:16 254

原创 leetcode刷题日记——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?问题分析:题目的意思是想要判断一个链表是否为回文,即正反一样。但是题目要求不能使用额外的空间,并且时间复杂度为O(n),题目的解题的关键就在于想到把前半部分

2015-12-28 21:39:16 357

原创 leetcode刷题日记——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 valid

2015-12-26 12:06:46 270

原创 leetcode刷题日记——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-12-26 11:29:26 252

原创 leetcode刷题日记——Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321问题分析:将一个数翻转过来,符号不变。题目看似简单,实际还要考虑越界的问题。所以用了long long int (不调试和参考别人例子想不到),其他部分就是一个是取得各位数字,另外一个技巧就是翻转的数字和原

2015-12-25 21:42:20 305

原创 leetcode刷题日记——Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For

2015-12-25 20:26:00 293

原创 leetcode刷题日记——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

2015-12-25 18:10:27 480

原创 leetcode刷题日记——Power of Two

Given an integer, write a function to determine if it is a power of two.问题分析:题目目标明显,判断一个数是否为2的指数幂。首先如果一个数不能被2整除,肯定排除。另外能整除的数中又分为,最终一直除以2之后,中途不终止的倒最变成一的肯定是,具体实现代码如下:class Solution {public: boo

2015-12-25 15:14:24 252

原创 leetcode刷题日记——Same Tree

Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.问题分析:判断二个树是否

2015-12-25 15:05:54 306

原创 leetcode刷题日记——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 fi

2015-12-25 14:50:30 354

原创 leetcode刷题日记——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

2015-12-25 10:47:12 220

原创 leetcode刷题日记——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?问题分析:判断一个单链表是否存在环,要求不使用额外的空间。刚开始对着题目发了半天呆,想着如果用循环,如果存在环就是死循环,后来想想是不是有什么策略来在循环过程中判断是否

2015-12-24 20:34:02 315

原创 leetcode刷题日记——Missing Number

iven an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm should r

2015-12-24 19:42:41 170

原创 leetcode刷题日记——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.

2015-12-24 19:09:03 283

原创 leetcode刷题日记——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

2015-12-24 16:47:10 189

原创 leetcode刷题日记——Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space. 问题分析:判断是个数是否是回文数(正反看都一样的数字),显然负数不是回文数。解决办法就是一次判断首尾是否一样就可以了,当然 可以考虑递归,但是有迭代的方法可以解决,题目要求不能要求额外的空间。这里采用把数字转化为字符串,然后判断。实现代码如下:

2015-12-24 15:15:32 236

原创 leetcode刷题日记—— Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is d

2015-12-24 13:44:09 232

原创 leetcode刷题日记——Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].问题分析:题目目标就是找出给定排序数组中的连续段,分段输出。解决这个问题我们只需要找出分段点就可以了,

2015-12-24 13:02:22 255

原创 leetcode刷题日记——Count and Say

The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "one

2015-12-24 12:27:27 244

原创 leetcode刷题日记——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↘c1 → c2 → c3↗ B: b1 → b2 → b3beg

2015-12-23 22:27:45 264

原创 leetcode刷题日记——Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit

2015-12-23 21:21:01 376

原创 leetcode刷题日记——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() -- Retur

2015-12-23 20:12:17 225

原创 leetcode刷题日记——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 following is not

2015-12-23 16:41:04 349

原创 leetcode刷题日记——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

2015-12-23 14:05:14 331

原创 leetcode刷题日记——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

2015-12-23 13:11:23 299

原创 leetcode刷题日记——Number of 1 Bits

Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 00000000

2015-12-23 12:44:25 300

原创 leetcode刷题日记——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, whe

2015-12-20 16:05:11 352

原创 leetcode刷题日记——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/ \15 7re

2015-12-20 15:55:34 344

原创 leetcode刷题日记——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.

2015-12-20 14:18:20 238

原创 leetcode刷题日记——Find Peak Element

A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in

2015-12-20 13:13:03 299

原创 leetcode刷题日记——Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3},1\2/3return [3,2,1].问题分析:这里考察的是二叉数的后序遍历,和前面的前序中序类似,不过这里三个题的解法都使用的递归

2015-12-20 12:44:27 270

原创 leetcode刷题日记——Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3},1\2/3return [1,2,3].问题分析:解题思想和中序遍历一样,采用递归,代码如下/** * Definition fo

2015-12-20 00:45:42 213

空空如也

空空如也

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

TA关注的人

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