08 2017 档案
摘要:题意大概是给定M×N的棋盘格,从左上到右下,只能向右或者向下走,每走一步需要加上棋盘格子内的数值(有正有负)。 需要随时保证当前的数值>=1。问初始需要最少的值是多少? 思路: 动态规划。用dp[i][j]代表当前最大的数值。首先求出dp[m][n],得出到达右下角的最优值。 然后再回溯求出从左上角
阅读全文
摘要:If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digits integers. For each integer in this list: Given a
阅读全文
摘要:Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element. We define an array is non-decr
阅读全文
摘要:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For exam
阅读全文
摘要:给定一个字符串S和有效单词的字典D,请确定可以插入到S中的最小空格数,使得最终的字符串完全由D中的有效单词组成。并输出解。 如果没有解则应该输出n/a 例如: 输入: S = “ilikealibaba” D = {"i","like","ali","liba","baba","alibaba"}
阅读全文
摘要:1. 猎人把一对兔子婴儿(一公一母称为一对)放到一个荒岛上,两年之后,它们生下一对小兔,之后开始每年都会生下一对小兔。生下的小兔又会以同样的方式继续繁殖。 2. 兔子的寿命都是x(x>=3)年,并且生命的最后一年不繁殖。 3. 如果岛上的兔子多于10对,那么猎人会每年在兔子们完成繁殖或者仙逝之后,从
阅读全文
摘要:题目: 给定一个包含1-n的数列,我们通过交换任意两个元素给数列重新排序。 求最少需要多少次交换,能把数组排成按1-n递增的顺序,(数组中的元素互不重复)。 比如 初始状态 5 4 3 2 1 。交换5和1的位置 得到 1 4 3 2 5,再交换4 2的位置得到 1 2 3 4 5.只需要两次即可。
阅读全文
摘要:Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the ave
阅读全文
摘要:Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binar
阅读全文
摘要:Given a binary tree with n nodes, your task is to check if it's possible to partition the tree to two trees which have the equal sum of values after r
阅读全文
摘要:转载自:http://blog.csdn.net/qq_14935437/article/details/71081546 OSI模型,即开放式通信系统互联参考模型(Open System Interconnection,OSI/RM,Open Systems InterconnectionRefe
阅读全文
摘要:一些容易记混的c++相关知识。 截图自:《王道程序员面试宝典》
阅读全文
摘要:Given a sorted array, two integers k and x, find the k closest elements to x in the array. The result should also be sorted in ascending order. If the
阅读全文
摘要:Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the or
阅读全文
摘要:B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right); 2.所有结点存储一个关键字; 3.非叶子结点的左指针指向小于其关键字的子树,右指针指向大于其关键字的子树; 如: B树的搜索,从根结点开始,如果查询的关键字与结点的关键字相等,那么就命中; 否则,如果查询关键字比结点
阅读全文
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4],t
阅读全文
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. For example, given the following ma
阅读全文
摘要:Print a binary tree in an m*n 2D string array following these rules: Example 1: Example 2: Example 3: Note: The height of binary tree is in the range
阅读全文
摘要:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: Construct the maximum tree by the given array a
阅读全文
摘要:Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. E
阅读全文
摘要:某餐馆有n张桌子,每张桌子有一个参数:a 可容纳的最大人数; 有m批客人,每批客人有两个参数:b人数,c预计消费金额。 在不允许拼桌的情况下,请实现一个算法选择其中一部分客人,使得总预计消费金额最大 示例1 输入 3 5 2 4 2 1 3 3 5 3 7 5 9 1 10 输出 20 示例1 输入
阅读全文
摘要:转载自:http://www.cppblog.com/darren/archive/2009/06/09/87224.html priority_queue 调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法实现,也算是堆的另外一种形式。 先写一个用
阅读全文
摘要:Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any oneof them. Two
阅读全文


浙公网安备 33010602011771号