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 ...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. 1 class Solution { 2 public: 3 string longestCommonPrefix(v...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:链表结点类型定义:1 class Node {2 public:3 int data = 0;4 Node *next = nullptr;5 6 Node(int d) {7 data = d;8 }9 };快行指针(runner)技巧:同时...
阅读全文
摘要: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 =...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:list构造函数://default:list l; //空的list//fill:list l(n); //n个元素, 元素默认初始化list l(n, value); //n个元素值为value//range:list l(fir...
阅读全文
摘要:deque(double-endedqueue)构造函数://default:deque d; //空的vector//fill:deque d(n); //n个元素的deque,元素默认初始化deque d(n, value); //...
阅读全文
摘要:vector构造函数://default:vector v; //空的vector//fill:vector v(n); //n个元素的vector,元素默认初始化vector v(n, value); //n个元素值为value的v...
阅读全文
摘要:1.1 实现一个算法,确定一个字符串的所有字符是否全都不同。不允许使用额外的数据结构。解答:这里假定字符集为ASCII码,可以与面试官沟通确认字符串使用的字符集。由于字符集是有限的,建立一个数组模拟的Hash表记录每个字符是否出现,线性扫描一次字符串即可,复杂度O(len(s)).如果字符集较大,需...
阅读全文
摘要:Problem Description 魔法师百小度也有遇到难题的时候—— 现在,百小度正在一个古老的石门面前,石门上有一段古老的魔法文字,读懂这种魔法文字需要耗费大量的能量和大量的脑力。 过了许久,百小度终于读懂魔法文字的含义:石门里面有一个石盘,魔法师需要通过魔法将这个石盘旋转X度,以使上...
阅读全文
摘要:问题描述:超市有4种包装的鸡蛋,分别是3个一盒,6个一盒,9个一盒和20个一盒。问顾客要买N个鸡蛋时,所有的组合方案。(Morgen Stanley 2014 Intern).还有找零钱问题要求输出所有方案,也是一个意思。核心代码: 1 void BuyEggsCore(vector &coins,...
阅读全文

浙公网安备 33010602011771号