06 2014 档案

翻转链表-迭代和递归双版本
摘要:将一个链表翻转,如 1->2->3->4 变成 4->3->2->1 的链表。这是一个非常著名的面试题,看似非常的简单,但实际上非常的tricky.实现方法可以有递归和迭代两种方法,这两个算法也都保证了in-place 和 one-pass. 所以效率还是很高的。这篇文章主要基于http://lee... 阅读全文

posted @ 2014-06-21 22:30 soyscut 阅读(2043) 评论(4) 推荐(0)

(转)C++重写、重载和重定义的区别
摘要:C++ 重写重载重定义区别(源自:http://blog.163.com/clevertanglei900@126/blog/static/111352259201102441934870/)1 成员函数重载特征: a 相同的范围(在同一个类中) b 函数名字相同 c 参数不同 d virtual关... 阅读全文

posted @ 2014-06-20 15:02 soyscut 阅读(207) 评论(0) 推荐(0)

Leetcode:Letter Combinations of a Phone Number
摘要:Description:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on ... 阅读全文

posted @ 2014-06-18 21:49 soyscut 阅读(209) 评论(0) 推荐(0)

Leetcode:Pow(x,n)
摘要:Description: Implement pow(x,n).分析: 求幂次运算,典型的分治算法来解。 因为pow(x,n/2)*pow(x,n/2) 有着重复运算,分治法就会非常快O(log n) 1 class Solution { 2 public: 3 double findval... 阅读全文

posted @ 2014-06-18 21:41 soyscut 阅读(196) 评论(0) 推荐(0)

Leetcode:Combination Sum
摘要:Description:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesame... 阅读全文

posted @ 2014-06-18 21:36 soyscut 阅读(350) 评论(0) 推荐(0)

Leetcode:Binary Tree Zigzag Level Order Traversal
摘要:Description:Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next ... 阅读全文

posted @ 2014-06-13 21:37 soyscut 阅读(96) 评论(0) 推荐(0)

Leetcode:Partition List
摘要:Description:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preser... 阅读全文

posted @ 2014-06-13 21:29 soyscut 阅读(121) 评论(0) 推荐(0)

Leetcode:Count and Say
摘要:Description:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is re... 阅读全文

posted @ 2014-06-13 21:08 soyscut 阅读(150) 评论(0) 推荐(0)

Leetcode:Triangle
摘要:Decription:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, gi... 阅读全文

posted @ 2014-06-13 20:53 soyscut 阅读(310) 评论(0) 推荐(0)

Leetcode: Subsets & SubsetsII
摘要:Subsets Description:Given a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solu... 阅读全文

posted @ 2014-06-13 20:46 soyscut 阅读(178) 评论(0) 推荐(0)

Leetcode:Convert Sorted List to Binary Search Tree
摘要:Description :Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.分析:这道题目简单版是把一个排序好的数组转成平衡的二叉树... 阅读全文

posted @ 2014-06-12 11:55 soyscut 阅读(255) 评论(0) 推荐(0)

Leetcode:Unique Binary Search Trees & Unique Binary Search Trees II
摘要:Unique Binary Search TreesGivenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a to... 阅读全文

posted @ 2014-06-12 11:22 soyscut 阅读(281) 评论(0) 推荐(0)

Leetcode::Longest Common Prefix && Search for a Range
摘要:一次总结两道题,两道题目都比较基础Description:Write a function to find the longest common prefix string amongst an array of strings.分析: 这道题目最重要的知道什么叫prefix前缀, 否则一不小心就做... 阅读全文

posted @ 2014-06-08 23:16 soyscut 阅读(204) 评论(0) 推荐(0)

Leetcode::Flatten Binary Tree to Linked List
摘要:Description:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The... 阅读全文

posted @ 2014-06-07 20:55 soyscut 阅读(184) 评论(0) 推荐(0)

Leetcode::JumpGame
摘要:Description:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents... 阅读全文

posted @ 2014-06-07 20:18 soyscut 阅读(211) 评论(0) 推荐(0)

Leetcode::Pathsum & Pathsum II
摘要:PathsumDescription: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 equa... 阅读全文

posted @ 2014-06-07 11:33 soyscut 阅读(170) 评论(0) 推荐(0)

Leetcode::Longest Consecutive Sequence
摘要:Description:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],... 阅读全文

posted @ 2014-06-07 11:09 soyscut 阅读(189) 评论(0) 推荐(0)

Leetcode: UniquePath II
摘要:Description:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and e... 阅读全文

posted @ 2014-06-05 17:30 soyscut 阅读(192) 评论(0) 推荐(0)

Leetcode::Subsets
摘要:Given a set of distinct integers,S, return all possible subsets.分析:题目就是给一个整数集合,给出所以的子集。 基本思想是递归或者说是迭代的方法。用前面得到的集合来构造后面的。但是怎样高效、方便的构造集合是关键点。比如,开始想到的是先生... 阅读全文

posted @ 2014-06-05 17:18 soyscut 阅读(184) 评论(0) 推荐(0)

Leetcode: 06/01
摘要:今天完成了三道题目,总结一下:1: Length of last word(细节实现题)此题有一些细节需要注意(比如 “a_ _” 最后一个单词是a, 而不是遇到空格就直接算成没有),别的基本就是模拟了。 1 class Solution { 2 public: 3 int lengthOf... 阅读全文

posted @ 2014-06-01 13:18 soyscut 阅读(235) 评论(0) 推荐(0)

导航