当前位置:网站首页>leetcode: 259. Smaller sum of three numbers
leetcode: 259. Smaller sum of three numbers
2022-08-04 14:37:00 【OceanStar's study notes】
题目来源
题目描述

class Solution {
public:
int threeSumSmaller(vector<int>& nums, int target){
}
};
题目解析
思路
- 先对数组排序
- 固定一个值,然后双指针碰撞.将所有符合条件的[l,r]The interval is counted into the result.
class Solution {
public:
int threeSumSmaller(vector<int>& nums, int target){
int res = 0;
std::sort(nums.begin(), nums.end());
for (int i = 0; i < nums.size(); ++i) {
int L = i + 1, R = nums.size() - 1;
while (L < R){
int sum = nums[i] + nums[L] + nums[R];
if(sum >= target){
R--;
}else{
res += (R - L);
L++;
}
}
}
return res;
}
};
边栏推荐
猜你喜欢

ICML 2022 | 图神经网络的局部增强

Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market

JCMsuite应用:倾斜平面波传播透过光阑的传输

浙江大学团队使用基于知识图谱的新方法,从空间分辨转录组数据中推断细胞间通信状况

X射线掠入射聚焦反射镜
![[Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution](/img/1c/3c8c323e6ee3406d202e07f85bab21.jpg)
[Beiya data recovery] IBM System Storage storage lvm information lost data recovery solution

This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean

leetcode:255 验证前序遍历序列二叉搜索树

Kyushu Cloud attended the Navigator Online Forum to discuss the current status, challenges and future of 5G MEC edge computing

理论篇1:深度学习之----LetNet模型详解
随机推荐
砺夏行动|九州云章津楠:开源不是少数人的运动,大众化才是源泉
【模型部署与业务落地】基于量化芯片的损失分析
兆骑科创创新创业大赛活动举办,线上直播路演,投融资对接
AOSP built-in APP franchise rights white list
Cisco-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)
centos7安装mysql急速版
四平方和,激光炸弹
Sum of four squares, laser bombs
Rust from entry to proficient 04-variables
LeetCode_模拟_中等_498.对角线遍历
LCP 06. 拿硬币-遍历
Oracle database user creation, restart, import and export
快解析结合千方百剂
【 HMS core 】 【 Media 】 online video editing service 】 【 material can't show, or network anomalies have been Loading state
ACL 2022 | 社会科学理论驱动的言论建模
Keycloak 6.0.0 正式发布,身份和访问管理系统
特殊品种的二次开户验资金额
爬虫——动作链、xpath、打码平台使用
NPDP|作为产品经理,如何快速提升自身业务素养?
C# 复制列表