LeetCode解题源代码链接集锦一
1. Two Sum--两数和
java:http://blog.segmentfault.com/code/1190000000450743
2. Add two numbers--两组链表数和
java:http://blog.segmentfault.com/code/1190000000450701
http://www.programcreek.com/2012/12/add-two-numbers/
注:K sum参考链接http://tech-wonderland.net/blog/summary-of-ksum-problems.html
3SUM--三数和
C++:http://www.cnblogs.com/codingmylife/archive/2012/08/30/2663796.html
4SUM--四数和
Python:http://chaoren.is-programmer.com/posts/45308.html
3. Median of two sorted arrays--两个有序数组的中位数
关键点:寻找最小的K数
java:http://blog.segmentfault.com/code/1190000000450951
4. Gas station--加油站问题
关键点:一层for循环,累加,出现负值抛弃之前的所有加油站位置
java:http://www.lifeincode.net/programming/leetcode-gas-station-java/
5.Max Points on a Line--直线上最多点
关键点:两层循环,斜率判断
C++:http://zhaohongze.com/wordpress/2013/12/09/leetcode-max-points-on-a-line/
java:http://rleetcode.blogspot.com/2014/01/max-points-on-linejava.html(可能被墙)
6.Roman to Integer--罗马切换阿拉伯数字
C++: http://fisherlei.blogspot.com/2012/12/leetcode-roman-to-integer.html
http://www.cnblogs.com/TenosDoIt/p/3793503.html
Integerto Roman--阿拉伯数字切换罗马
C++:http://www.cnblogs.com/TenosDoIt/p/3793503.html
7.Longest Substring Without Repeating Characters--不重复最长子串长度
C++:http://leetcode.com/2011/05/longest-substring-without-repeating-characters.html
8.Merge Sorted Array--合并两个有序数组
关键点:从后比较,减少后移的操作
C++:http://www.cnblogs.com/remlostime/archive/2012/11/16/2772935.html
Java:http://blog.csdn.net/xudli/article/details/8492041
Merge Two Sorted Lists--合并两个有序链表
关键点:一个temp指针,从头比较,可以采用递归
C++:http://www.cnblogs.com/codingmylife/archive/2012/09/27/2705286.html
Java:http://www.programcreek.com/2012/12/leetcode-merge-two-sorted-lists-java/(没有采取递归来做)
Merge k Sorted Lists--合并k个有序链表
关键点:1)可以不断的两两链表合并,采用上面的策略
2)大小为k的堆排序
C++:http://blog.sina.com.cn/s/blog_60b5450101017tcr.html
Java:http://blog.csdn.net/linhuanmars/article/details/19899259(分治二分和k大小堆的排序)
9.Insert Intervals--数学区间插入
关键点:先排序,然后再循环一遍
C++:http://www.cnblogs.com/obama/archive/2013/08/27/3284050.html
Java:http://www.cnblogs.com/lautsie/archive/2013/08/12/3254191.html
Merge Intervals--合并数学区间
关键点:先排序,然后再循环一遍
C++:http://19542002.blog.163.com/blog/static/1339323822013227915049/
Java:http://blog.csdn.net/worldwindjp/article/details/21612731
10.String to Integer (atoi)--string与int的切换
关键点:空格,异常输入的判断
Java:http://blog.csdn.net/beiyetengqing/article/details/8458725
11.Single Number--只出现一次的数字
关键点:不允许额外的空间,采用异或判断,异或符号^
C++:http://blog.csdn.net/magisu/article/details/13169283
Java:http://www.cnblogs.com/changchengxiao/p/3413294.html
Single Number II--只出现一次的数字
关键点:取模问题
C++:http://blog.csdn.net/jiadebin890724/article/details/23306837
http://blog.csdn.net/waitfor_/article/details/21163985
Java:http://xingxjhui.blog.163.com/blog/static/2155451642014017104633868/
12.Balanced Binary Tree--平衡二叉树
关键点:了解平衡二叉树的定义,左子树右子树高度差不大于1
http://kimibob.blog.163.com/blog/static/163873051201153093851369/
C++:http://blog.csdn.net/pickless/article/details/11885301
Java:http://blog.sina.com.cn/s/blog_71d59f9a01018fyh.html
13.Convert Sorted Array to Binary Search Tree--排序数组二叉查找树的互换
关键点:了解二叉查找树的定义,题目要求高度平衡是左右子树高度差不超过1
二分递归,每次都选择当前长度的中间作为根节点,保证高度,然后依次递归
C++:http://jiyuede.blog.163.com/blog/static/332519212012112023814496/
Java:http://www.programcreek.com/2013/01/leetcode-convert-sorted-array-to-binary-search-tree-java/
Convert Sorted List to Binary Search Tree--排序链表二叉查找树的互换
关键点:没法在O(1)时间获取中间位置,所以需要获取链表的长度,然后从下面开始构造二叉树
参考链接:http://leetcode.com/2010/11/convert-sorted-list-to-balanced-binary.html(英文)
C++:http://www.2cto.com/kf/201402/282179.html
Java:http://blog.csdn.net/bigapplestar/article/details/12587331
14.Valid Number--字符串是合法的数字
关键点:列举出所有情况,声明一个针对所有情况的状态矩阵
参考链接:http://www.2cto.com/kf/201403/284023.html http://blog.csdn.net/doc_sgl/article/details/13505069
C++:http://www.2cto.com/kf/201403/284023.html
Java:http://blog.csdn.net/linhuanmars/article/details/23809661
正则表达式的解法:http://www.2cto.com/kf/201310/251338.html