摘要: Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".class Solution {public: string addBinary(string a, string b) { // Start typing your C/C++ solution below // DO NOT write int main() function int length1=a.si 阅读全文
posted @ 2012-12-27 19:44 和道一文字 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 问题描述:Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie,a≤b≤c≤d)The solution set must not contain duplicate quadruple 阅读全文
posted @ 2012-12-27 18:57 和道一文字 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 1)到底用什么数据结构去存储元素,链表,数组,堆,数,图?2)如何去重?3)如何找两个链表中相同的元素?4)什么是动态规划?5)什么是贪心算法?6)什么是分治算法?7)动态规划算法跟贪心算法有什么区别——这个曾今在电面的时候被问到过。 阅读全文
posted @ 2012-12-27 16:56 和道一文字 阅读(233) 评论(0) 推荐(0) 编辑
摘要: http://www.leetcode.com/onlinejudge里面的第二题其实这是ThreeSum问题的一个扩展:我写的第一个版本是这样的这应该算一个典型的组合优化问题么???class Solution2 {public: int threeSumClosest(vector<int> &num, int target) { // Start typing your C/C++ solution below // DO NOT write int main() function int count=num.size(); ... 阅读全文
posted @ 2012-12-27 09:34 和道一文字 阅读(277) 评论(0) 推荐(0) 编辑