摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu... 阅读全文
posted @ 2014-04-03 19:05 Eason Liu 阅读(207) 评论(0) 推荐(0) 编辑
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.这题先得知道啥叫Anagrams,知道后其实很简单。首先简单介绍一下Anagram(回文构词法)。Anagrams是指由颠倒字母顺序组成的单词,比如“dormitory”颠倒字母顺序会变成“dirty room”,“tea”会变成“eat”。回文构词法有一个特点:单词里的字母的种类和数目没有改变,只是改变了字母的排列顺序。For example:Input: [" 阅读全文
posted @ 2014-04-03 18:01 Eason Liu 阅读(7046) 评论(0) 推荐(0) 编辑
摘要: Find next higher number with same digits.Example 1 : if num = 25468, o/p = 25486Example 2 : if num = 21765, o/p = 25167Example 3 : If num = 54321, o/p = 54321 (cause it's not possible to gen a higher num than tiz with given digits ).Google的面试题,实际上就是next_permutation。 阅读全文
posted @ 2014-04-03 17:36 Eason Liu 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 题目描述:把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。输入:输入包括一个整数N(1 2 #include 3 using namespace std; 4 5 int a[1501]; 6 7 int getMin(int a, int b, int c) 8 { 9 int tmp = a < b ? a : b;10 return c < tmp ? c : tmp;11 }12 13 void init()14 {15 ... 阅读全文
posted @ 2014-04-03 17:20 Eason Liu 阅读(605) 评论(1) 推荐(0) 编辑
摘要: 找出两个单链表里交叉的第一个元素解法:分别遍历list1、list2,计算得到L1,L2;比较最后结点是否相等,相等则表明是两个链表是交叉的如果交叉:长的链表先移动|L1-L2|步,再逐个比较,等到第一个交点! 阅读全文
posted @ 2014-04-03 16:11 Eason Liu 阅读(314) 评论(0) 推荐(0) 编辑
摘要: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBANC"T="ABC"Minimum window is"BANC".Note:If there is no such window in S that covers all characters in T, return the emtpy 阅读全文
posted @ 2014-04-03 15:30 Eason Liu 阅读(184) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.后序遍历! 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode... 阅读全文
posted @ 2014-04-03 14:27 Eason Liu 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked listL: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 to{1,4,2,3}.OH! MY GOD! I HATE LINKED LIST!看似简单,实现起来总会遇到各种指针错误,写程序之前最好先在纸上好好画画,把各种指针关系搞搞清楚。本题的想法就是先将列表平分成两份,后一份逆序,然 阅读全文
posted @ 2014-04-03 13:31 Eason Liu 阅读(793) 评论(0) 推荐(0) 编辑