自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 LeetCode :: 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

2014-08-07 23:27:15 880

原创 Leetcode :: 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 u

2014-08-05 21:52:31 1113

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

2014-08-04 22:00:43 921

原创 LeetCode :: Convert Sorted Array (link list) to Binary Search Tree [tree]

1.Given an array where elements are sorted in ascending order, convert it to a height balanced BST.2.Given a singly linked list where elements are sorted in ascending order, convert it to a heig

2014-07-21 23:02:17 1646

原创 LeetCode :: Binary Tree Zigzag Level Order Traversal [tree, BFS]

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary

2014-07-20 17:58:45 897

原创 LeetCode :: 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

2014-07-19 22:50:26 788

原创 LeetCode :: Candy

class Solution {public: int candy(vector &ratings) { int m = ratings.size(); int sum = 0; vector candy(m); candy[0] = 1; for(int i = 1; i < m; i++

2014-07-19 16:10:00 632

原创 LeetCode :: Sum Root to Leaf Numbers [tree、dfs]

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the to

2014-07-17 22:24:29 837

原创 LeetCode详细分析 :: Recover Binary Search Tree [Tree]

Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis

2014-07-16 22:41:31 874

原创 LeetCode :: Validate Binary Search Tree[详细分析]

Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th

2014-07-10 23:57:39 1123

原创 LeetCode:: Unique Binary Search Trees[详细分析]

Unique Binary Search Trees My SubmissionsGiven n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 uniqu

2014-07-06 20:42:31 1370

原创 LeetCode :: 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 t

2014-06-23 23:16:05 865

原创 LeetCode :: Insertion Sort List [详细分析]

Sort a linked list using insertion sort.仍然是一个非常简洁的题目,让我们用插入排序给链表排序;这里说到插入排序,可以来回顾一下, 最基本的入门排序算法,就是插入排序了;时间复杂度为n^2,最基本的插入排序是基于数组实现的,下面给出基于数组实现的插入排序,来体会一个插入排序的思想;以下仅为数组实现,不是解题代码,没兴趣可以跳过。vo

2014-06-23 00:05:02 1529

原创 LeetCode::Sort List 详细分析

Sort a linked list in O(n log n) time using constant space complexity.这道题目非常简短的一句话,给链表排序,看到nlogn,我们可以来简单复习一下排序。首先说一下这个nlogn的时间复杂度(根据决策树我们可以得出这个界限),是基于比较排序的最小上限,也就是说,对于没有一定范围情况的数据来说,最快的排序思路就是归并和快速排

2014-06-21 22:38:57 902

原创 LeetCode::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->1-

2014-06-19 22:13:27 1251

原创 草稿暂存

class Solution {public: ListNode *deleteDuplicates(ListNode *head) { if (head == NULL) return NULL; bool isDup; ListNode *pos = head, *next_pos =

2014-06-19 09:59:11 963

原创 C++中map、hash_map、unordered_map、unordered_set通俗辨析

标题中提到的四种容器,对于概念不清的人来说,经常容易弄混淆。这里我不去把库里面复杂的原码拿出剖析,这个如果有兴趣其实完全可以查C++Reference,网上的原码是最权威和细致的了,而且我觉得有耐心直接认真看原码的人,也不需要我这篇速记博文了,所以我这里还是讲的通俗一些,把它们区分的七七八八。一、hash_map、unordered_map这两个的内部结构都是采用哈希表来实现。区别在哪里?

2014-04-06 21:53:26 25167 4

原创 LeetCode :: Reverse Words in a String

Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".这是LeetCode最新的一道题目,涉及到string的处理,好像之前我都没随机到字符串处理的问题,不得不说C++的字符串处理比C方便太

2014-04-01 14:46:16 1153

原创 LeetCode :: Gray Code[正确解答,真正考察点剖析]

这道题目,一般google之会发现很多答案都很简短,代码也就几行,但是你能写到这个代码的前提是,你知道什么叫做格雷码,并且格雷码和二进制码之间的转换公式。可是我觉得这道题根本就不是一道考察你知识点是否全面的题目,就算之前不知道格雷码的知识,仍然是可以写出来的,具体参见我的分析和代码。

2014-03-30 21:25:40 2161

原创 LeetCode ::Merge Sorted Array[最简短代码]

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

2014-03-29 23:29:55 942

原创 LeetCode :: Linked List Cycle I and II

I.Given a linked list, determine if it has a cycle in it.II. Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Can you solve it without using extra s

2014-03-29 22:21:16 946

原创 LeetCode :: Maximum Subarray 详细分析

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha

2014-03-28 11:34:58 1977

原创 LeetCode :: 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.合并两个排好序的链表,这里重新设置两个指针,l3、trail,一个指示新链表的头结点,另一个指示新链表的最末有

2014-03-25 16:56:11 775

原创 LeetCode :: 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.这道题目,可以和之前的LeetCode ::

2014-03-24 23:31:42 795

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

2014-03-24 22:45:39 599

原创 LeetCode :: Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.很

2014-03-24 21:28:39 701

原创 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 A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,

2014-03-24 21:11:02 657

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

2014-03-24 17:12:22 668

原创 LeetCode :: 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

2014-03-24 15:05:52 897

原创 LeetCode :: 3.Path Sum [树类题目分析]

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum

2014-03-22 17:43:48 636

原创 [面试小题目] SAP的一道面试题

这题目是一个同学面SAP的时候问的,题目很比较简单,给你一个string,eg: my book is good 然后要求把每个单词都颠倒顺序输出。 output::ym koob si doog;最简单的思路肯定是先写一个对于一个不含空格的单词的颠倒程序,然后遇到一次空格调用一次,最后拼起来。那如果题目要求你把单词颠倒呢?应该怎么写? output: good is book my; 所

2014-03-22 13:47:13 1137

原创 LeetCode :: 2.Minimum Depth of Binary Tree [树类题目分析]

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.作为树分类的第二篇,寻找最浅的那片叶子。这里是一个后序遍历的过程。P

2014-03-21 23:09:08 729

原创 LeetCode :: 1.Balanced Binary Tree [树类题目分析]

Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtreesof every node never diff

2014-03-21 21:38:06 997

转载 LeetCode 各题目难度已经面试频率

1Two Sum25arraysort    setTwo Pointers2Add Two Numbers34linked listTwo Pointers   

2014-03-20 23:07:48 1839

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

2014-03-20 22:26:32 955

原创 LeetCode :: 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 line i is at (i, ai) and (i

2014-03-13 22:51:51 836

原创 LeetCode :: Palindrome

今天真是lucky,随机到的题目都比较简单。这里判断回文数字。Determine whether an integer is a palindrome. Do this without extra space.题目也是很简短,唯一值得注意的是,负数全部不是回文数字,一开始我没考虑到负数,所以没AC。这里用 long long 来存在取反的数字,来避免越界问题。class Solut

2014-03-13 17:01:57 638

原创 LeetCode :: Reverse Integer

Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321题目比较简单,给出的函数原型int reverse(int x);这里让我费解的地方是展开讨论的这句话:Did you notice that the reversed integer migh

2014-03-13 16:45:35 664

原创 LeetCode :: Pow(x, n)

题目要求很简洁,Implement pow(x, n),没了。函数的原型是这样的:double pow(double x, int n) ;一、这里最容易想到的,肯定是时间复杂度为O(N), 利用一个递归,我试了一下,果然和想的一样 TL。二、把pow分解为 pow(x, n / 2) ,T(N) = T(N / 2) + O (1),这里的时间复杂度利用master method,显而易见是O(

2014-03-13 16:28:24 951

原创 LeetCode 开篇

经历了一些人,一些事,深深地认识到自己的不足,感觉应该脚踏实地地去工作、去学习,冰冻三尺,非一日之寒。首先,先从Leetcode这样一个经典的网站开始吧,一天写一些,更一些,好像网上有很多题解,但是好多都写得不是那么清楚或者写的很晦涩,我想写得详细一点,把每题涉及的问题都详细的分析与阐释一下,算是留给自己复习用吧。加油吧,骚年。

2014-03-13 15:40:34 733

空空如也

空空如也

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

TA关注的人

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