05 2014 档案

摘要:Implementint sqrt(int x).Compute and return the square root ofx. 1 class Solution { 2 public: 3 int sqrt(int x) { 4 if (x mid) { // 不要用x ... 阅读全文
posted @ 2014-05-21 12:30 小菜刷题史 阅读(115) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings. 1 class Solution { 2 public: 3 string longestCommonPrefix(v... 阅读全文
posted @ 2014-05-21 12:00 小菜刷题史 阅读(114) 评论(0) 推荐(0)
摘要:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the ord... 阅读全文
posted @ 2014-05-21 11:42 小菜刷题史 阅读(187) 评论(0) 推荐(0)
摘要: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, given the fol... 阅读全文
posted @ 2014-05-21 11:11 小菜刷题史 阅读(149) 评论(0) 推荐(0)
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t... 阅读全文
posted @ 2014-05-21 10:46 小菜刷题史 阅读(113) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2014-05-20 23:42 小菜刷题史 阅读(151) 评论(0) 推荐(0)
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2014-05-20 22:44 小菜刷题史 阅读(137) 评论(0) 推荐(0)
摘要: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-05-20 18:33 小菜刷题史 阅读(127) 评论(0) 推荐(0)
摘要:链表结点类型定义:1 class Node {2 public:3 int data = 0;4 Node *next = nullptr;5 6 Node(int d) {7 data = d;8 }9 };快行指针(runner)技巧:同时... 阅读全文
posted @ 2014-05-20 18:13 小菜刷题史 阅读(366) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =... 阅读全文
posted @ 2014-05-20 12:31 小菜刷题史 阅读(150) 评论(0) 推荐(0)
摘要:Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe... 阅读全文
posted @ 2014-05-20 12:10 小菜刷题史 阅读(107) 评论(0) 推荐(0)
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文
posted @ 2014-05-20 11:51 小菜刷题史 阅读(146) 评论(0) 推荐(0)
摘要:list构造函数://default:list l; //空的list//fill:list l(n); //n个元素, 元素默认初始化list l(n, value); //n个元素值为value//range:list l(fir... 阅读全文
posted @ 2014-05-19 23:02 小菜刷题史 阅读(224) 评论(0) 推荐(0)
摘要:deque(double-endedqueue)构造函数://default:deque d; //空的vector//fill:deque d(n); //n个元素的deque,元素默认初始化deque d(n, value); //... 阅读全文
posted @ 2014-05-19 22:03 小菜刷题史 阅读(282) 评论(0) 推荐(0)
摘要:vector构造函数://default:vector v; //空的vector//fill:vector v(n); //n个元素的vector,元素默认初始化vector v(n, value); //n个元素值为value的v... 阅读全文
posted @ 2014-05-19 21:12 小菜刷题史 阅读(293) 评论(0) 推荐(0)
摘要:1.1 实现一个算法,确定一个字符串的所有字符是否全都不同。不允许使用额外的数据结构。解答:这里假定字符集为ASCII码,可以与面试官沟通确认字符串使用的字符集。由于字符集是有限的,建立一个数组模拟的Hash表记录每个字符是否出现,线性扫描一次字符串即可,复杂度O(len(s)).如果字符集较大,需... 阅读全文
posted @ 2014-05-19 13:21 小菜刷题史 阅读(571) 评论(0) 推荐(0)
摘要:Problem Description 魔法师百小度也有遇到难题的时候—— 现在,百小度正在一个古老的石门面前,石门上有一段古老的魔法文字,读懂这种魔法文字需要耗费大量的能量和大量的脑力。 过了许久,百小度终于读懂魔法文字的含义:石门里面有一个石盘,魔法师需要通过魔法将这个石盘旋转X度,以使上... 阅读全文
posted @ 2014-05-16 19:51 小菜刷题史 阅读(396) 评论(0) 推荐(0)
摘要:问题描述:超市有4种包装的鸡蛋,分别是3个一盒,6个一盒,9个一盒和20个一盒。问顾客要买N个鸡蛋时,所有的组合方案。(Morgen Stanley 2014 Intern).还有找零钱问题要求输出所有方案,也是一个意思。核心代码: 1 void BuyEggsCore(vector &coins,... 阅读全文
posted @ 2014-05-13 13:33 小菜刷题史 阅读(354) 评论(0) 推荐(0)