摘要: 顾名思义,贪心算法总是作出在当前看来最好的选择。也就是说贪心算法并不从整体最优考虑,它所作出的选择只是在某种意义上的局部最优选择。当然,希望贪心算法得到的最终结果也是整体最优的。虽然贪心算法不能对所有问题都得到整体最优解,但对许多问题它能产生整体最优解。如单源最短路经问题,最小生成树问题等。在一些情 阅读全文
posted @ 2017-01-31 07:13 CodesKiller 阅读(4756) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文
posted @ 2017-01-31 05:44 CodesKiller 阅读(117) 评论(0) 推荐(0) 编辑
摘要: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example:Given a = 1 and b = 2, return 3. 此题讲解全部都在bit m 阅读全文
posted @ 2017-01-31 05:25 CodesKiller 阅读(96) 评论(0) 推荐(0) 编辑
摘要: WIKI Bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a word. Computer programming tasks that req 阅读全文
posted @ 2017-01-31 05:21 CodesKiller 阅读(382) 评论(0) 推荐(0) 编辑
摘要: You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contai 阅读全文
posted @ 2017-01-31 03:21 CodesKiller 阅读(215) 评论(0) 推荐(0) 编辑
摘要: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai 阅读全文
posted @ 2017-01-31 02:33 CodesKiller 阅读(97) 评论(0) 推荐(0) 编辑
摘要: Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 此题主要考察数学知识,这里面注意,如果String的值要不断的改变的话,就最好用St 阅读全文
posted @ 2017-01-31 02:12 CodesKiller 阅读(77) 评论(0) 推荐(0) 编辑
摘要: Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. Note: 此题考查数学和数组的结合,直接上代码: public class Solu 阅读全文
posted @ 2017-01-30 10:26 CodesKiller 阅读(110) 评论(0) 推荐(0) 编辑
摘要: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leadin 阅读全文
posted @ 2017-01-30 07:44 CodesKiller 阅读(135) 评论(0) 推荐(0) 编辑
摘要: There is a fence with n posts, each post can be painted with one of the k colors. You have to paint all the posts such that no more than two adjacent 阅读全文
posted @ 2017-01-30 07:36 CodesKiller 阅读(136) 评论(0) 推荐(0) 编辑