上一页 1 2 3 4 5 6 7 8 9 ··· 14 下一页
摘要: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8 1 /** 2 * Definition 阅读全文
posted @ 2014-03-20 13:16 小菜刷题史 阅读(133) 评论(0) 推荐(0) 编辑
摘要: Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100". 1 class Solution { 2 public: 3 string addBinary(string a, string b) { 4 string ans; 5 int carry = 0; 6 int sum = 0; 7 int i = a.size() - 1, j = b.size() - 1; 8 ... 阅读全文
posted @ 2014-03-20 12:54 小菜刷题史 阅读(357) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 int * recor... 阅读全文
posted @ 2014-03-20 12:33 小菜刷题史 阅读(215) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 int ans = 0; 5 ... 阅读全文
posted @ 2014-03-20 12:22 小菜刷题史 阅读(132) 评论(0) 推荐(0) 编辑
摘要: There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candies than their neighbors.What is the minimum candies you mu 阅读全文
posted @ 2014-03-20 12:18 小菜刷题史 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 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 s 阅读全文
posted @ 2014-03-19 22:52 小菜刷题史 阅读(162) 评论(0) 推荐(0) 编辑
摘要: You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?到达 n 有两种途径:从 n - 1 走一步 or 从 n - 2 走两步.所以 f(n) = f(n - 1) + f (n - 2), 即斐波那契数列。可以迭代求解或者直接用通项公式。 1 class Solution { 2 public: 3 int clim... 阅读全文
posted @ 2014-03-19 22:24 小菜刷题史 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list. 1 class Solution { 2 public: 3 vector plusOne(vector &digits) { 4 int d = digits.size(); 5 int sum = 0, car... 阅读全文
posted @ 2014-03-19 22:13 小菜刷题史 阅读(188) 评论(0) 推荐(0) 编辑
摘要: You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place? 1 class Solution { 2 public: 3 void rotate(vector > &matrix) { 4 int n = matrix.size(); 5 for(int i = 0; i < n / 2; ++i) { 6 for(int j ... 阅读全文
posted @ 2014-03-19 22:02 小菜刷题史 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文
posted @ 2014-03-19 21:27 小菜刷题史 阅读(116) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 14 下一页