leetcode
文章平均质量分 77
ysc_ysc
这个作者很懒,什么都没留下…
展开
-
Add Two Numbers
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 link原创 2015-03-08 21:30:53 · 363 阅读 · 0 评论 -
Two Sum
最近开始刷leetcode了,感觉和pat相比,这个更看重算法,对时间复杂度的要求更高,而且最关键的是给测试用例,不像PAT上错了就各种猜猜猜,对输出格式也不用这么麻烦。 第一次刷leetcode还是有点不习惯,第一题就纠结了好久。。。 题目要求如下: Given an array of integers, find two numbers such that they add up原创 2015-03-07 14:46:06 · 504 阅读 · 0 评论 -
Xsum问题总结
LeetCode前面有好几题都是XSum,比如2Sum,3Sum,还有4Sum,刷的有点疲劳了。下面就总结一下吧。 2Sum最简单,先对数据进行排序,如果用STL的sort快排,时间复杂度为O(nlogn),然后设置两个指针,一个初始化为数组的头,一个初始化在数组的尾,然后两边向中间扫描,如果当前两个指针指向的数的和正好是target,那么就保存当前数对(注意先入栈从头开始的那个指针的数值,后入原创 2015-03-24 14:08:02 · 1084 阅读 · 0 评论 -
二分搜索及其变形讨论
最近刷leetcode的时候遇到了不少二分查找的题,二分查找是非常高效的查找策略,但是有一个前提就是数组必须是有序的。 1. 对于标准的二分搜索,针对的是没有重复元素的有序数组,每个元素只出现一次。标准的二分搜索的代码很简洁,对于程序员来讲最好会背 int std_binary_search(int v[], int n, int target) { int l,r,m; l原创 2015-04-15 19:46:39 · 530 阅读 · 0 评论