大致题意就是给定N个数,找出满足第i个数到第j个数的和SUM等于M(如果找不到,也可以找SUM-M>0差值最小)的i和j,并输出i-j。 思路:这题可以用二分法做,但是二分法边界值条件太多,容易出错,推荐使用two pointers。这题用的是two pointers同向扫描法,固定左边界,移动右边 ...
分类:
其他好文 时间:
2020-02-12 13:06:56
阅读次数:
61
这道题要求两个有序数组,找出中间位置的平均值; 解题思路: 1、取A数组的中间位置mid的值key,去B数组中查找最靠近key且小于等于key的位置index; 2、将原数组切成三段,index和mid之前数组的为新的left数组;right1跟right2为新的right数组;mid到right1 ...
分类:
其他好文 时间:
2020-02-12 12:51:16
阅读次数:
52
更多LeetCode解题详解 Easy Given an array arr of integers, check if there exists two integers N and M such that N is the double of M ( i.e. N = 2 * M). More ...
分类:
其他好文 时间:
2020-02-12 00:59:17
阅读次数:
85
1 """ 2 Given two strings text1 and text2, return the length of their longest common subsequence. 3 A subsequence of a string is a new string generate ...
分类:
其他好文 时间:
2020-02-12 00:23:03
阅读次数:
70
LeetCode 0167: Two Sum II Input array is sorted【Python】 题目 "英文题目链接" Given an array of integers that is already sorted in ascending order\ , find two n ...
分类:
编程语言 时间:
2020-02-12 00:19:27
阅读次数:
74
这是一道简单应用线段树的题 代码也是书上的,敲一边熟悉一下 #include <iostream>#include <cstdio>using namespace std;const int MAX=1e5+10;long long sum[MAX<<2],add[MAX<<2]; void up_ ...
分类:
其他好文 时间:
2020-02-11 19:07:08
阅读次数:
53
Table: Person + + + | Column Name | Type | + + + | PersonId | int | | FirstName | varchar | | LastName | varchar | + + + PersonId is the primary key c ...
分类:
其他好文 时间:
2020-02-11 17:41:53
阅读次数:
68
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domino is a tile with two numbers from 1 to 6 - one on ...
分类:
其他好文 时间:
2020-02-11 11:48:25
阅读次数:
101
Two Sum类 首先是基本的Two Sum题解 用hashmap 时间复杂度O(n),空间复杂度O(n),每一次首先找hashmap中有没有target - nums[i], 如果没有将nums[i]入map 用双指针法,时间复杂度O(n + nlogn), 空间复杂度O(1) 首先要对数组进行排 ...
分类:
其他好文 时间:
2020-02-11 09:28:14
阅读次数:
43
//add,懒标记,给以当前节点为根的子树中的每一个点加上add(不包含根节点) // #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef ...
分类:
其他好文 时间:
2020-02-11 09:22:13
阅读次数:
70