摘要:
LeetCode34. Find First and Last Position of Element in Sorted Array 题意:找出指定元素出现的范围,Ologn 思路:两次二分 class Solution { public: vector<int> searchRange(vect 阅读全文
摘要:
454. 4Sum II 题意:给四个数组,每个数组内取一个数使得四个数和为0,问有多少种取法 思路:枚举为On4,考虑两个数组,On2枚举所有可能的和,将和的出现次数存入map中,On2枚举另两个数组,看是否加和为0 class Solution { public: int fourSumCoun 阅读全文
摘要:
呜呜呜 递归好不想写qwq 求“所有情况”这种就递归 17. Letter Combinations of a Phone Number 题意:在九宫格上按数字,输出所有可能的字母组合 思路:递归回溯求解 递归保存的是每层的状态,因此每层的 str 不应该改,而是更改str和idx后进入到下一层 c 阅读全文
摘要:
11. Container With Most Water 题意:取两根求最大体积 思路:使用两个指针分别指向头和尾,然后考虑左右两根: 对于小的那根,如果选择了它,那么能够产生的最大体积一定是当前的情况:因为当前情况体积=这根长度 * 当前距离,以后的话长度一定是左右边界的min,即<=这根长度, 阅读全文
摘要:
网址:https://www.nowcoder.com/acm/contest/201#question A.签到 手速石头剪刀布 #include <cstdio> #include <algorithm> using namespace std; int main() { int a, b, c 阅读全文