摘要: Q:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions a 阅读全文
posted @ 2013-09-19 23:50 summer_zhou 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Q:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, givenn= 2, return[0,1,3,2]. Its gray code 阅读全文
posted @ 2013-09-19 23:20 summer_zhou 阅读(282) 评论(0) 推荐(0) 编辑
摘要: Q:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory. 阅读全文
posted @ 2013-09-19 16:59 summer_zhou 阅读(262) 评论(0) 推荐(0) 编辑
摘要: Q:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.A: 用字符串模拟数字相乘。keyPoints:1.先把字符串转换成int数组,再对位相乘。2.将int数组转换成字符串。注意:这里字符串第0位表示的应是数字的高位,所以最后需要将字符串reverse一下 string multiply(string num1, string n... 阅读全文
posted @ 2013-09-19 14:55 summer_zhou 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Q:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: Yo 阅读全文
posted @ 2013-09-19 10:04 summer_zhou 阅读(141) 评论(0) 推荐(0) 编辑