摘要: 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 小菜刷题史 阅读(131) 评论(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 小菜刷题史 阅读(214) 评论(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 小菜刷题史 阅读(131) 评论(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 小菜刷题史 阅读(155) 评论(0) 推荐(0) 编辑