摘要:将一个链表翻转,如 1->2->3->4 变成 4->3->2->1 的链表。这是一个非常著名的面试题,看似非常的简单,但实际上非常的tricky.实现方法可以有递归和迭代两种方法,这两个算法也都保证了in-place 和 one-pass. 所以效率还是很高的。这篇文章主要基于http://lee...
阅读全文
摘要:C++ 重写重载重定义区别(源自:http://blog.163.com/clevertanglei900@126/blog/static/111352259201102441934870/)1 成员函数重载特征: a 相同的范围(在同一个类中) b 函数名字相同 c 参数不同 d virtual关...
阅读全文
摘要:Description:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on ...
阅读全文
摘要:Description: Implement pow(x,n).分析: 求幂次运算,典型的分治算法来解。 因为pow(x,n/2)*pow(x,n/2) 有着重复运算,分治法就会非常快O(log n) 1 class Solution { 2 public: 3 double findval...
阅读全文
摘要:Description:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesame...
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:Description :Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.分析:这道题目简单版是把一个排序好的数组转成平衡的二叉树...
阅读全文
摘要: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...
阅读全文
摘要:一次总结两道题,两道题目都比较基础Description:Write a function to find the longest common prefix string amongst an array of strings.分析: 这道题目最重要的知道什么叫prefix前缀, 否则一不小心就做...
阅读全文
摘要:Description:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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],...
阅读全文
摘要: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...
阅读全文
摘要:Given a set of distinct integers,S, return all possible subsets.分析:题目就是给一个整数集合,给出所以的子集。 基本思想是递归或者说是迭代的方法。用前面得到的集合来构造后面的。但是怎样高效、方便的构造集合是关键点。比如,开始想到的是先生...
阅读全文
摘要:今天完成了三道题目,总结一下:1: Length of last word(细节实现题)此题有一些细节需要注意(比如 “a_ _” 最后一个单词是a, 而不是遇到空格就直接算成没有),别的基本就是模拟了。 1 class Solution { 2 public: 3 int lengthOf...
阅读全文