
leetcode
Shellphon
写代码啊写代码
展开
-
leetcode002:3sum closest
我去,时隔好几天才真的来解决第二个问题,太懒了,没怎么去思考。还是参考了下网上其他人的做法,才知道自己想的太复杂了,在判断指针左右移的时候纠结了。但其实算法跟第一题大致相同的,同样的思路解决o^2问题,再者就是如何去判断是否靠近了,这部分需要注意的应该就是判断的是绝对值而不是单纯相减.public class Solution { public int threeSumClosest(in原创 2012-12-02 20:30:52 · 739 阅读 · 0 评论 -
leetcode003:4 sum
嗯嗯,这次是4sum题了。4SumGiven an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the s原创 2012-12-03 23:51:55 · 521 阅读 · 0 评论 -
leetcode004:add binary
莫非深夜真的coder最有灵感的时候?题目:/** * Given two binary strings, return their sum (also a binary string). * For example, * a = "11" * b = "1" * Return "100". * */思路:1.当字符串有一个为空或者为0时,相当于答案取决于另一个原创 2012-12-07 00:43:45 · 650 阅读 · 0 评论 -
leetcode005:Add 2 numbers
Add Two NumbersYou 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 an原创 2012-12-11 23:12:06 · 823 阅读 · 0 评论 -
leetcode001:3sum solution
leetcode网站,提供了一些算法题,还有内嵌了c++和java的编辑器,提供运行测试。所以决定弥补自己算法的不足,多学习多思考实现。第一道题就难倒我了= =||题目如下3SumGiven an array S of n integers, are there elements a, b, c in S such that a + b + c = 0?原创 2012-11-27 23:36:16 · 757 阅读 · 0 评论