LeetCode-16-最接近的三数之和

【Leetcode】16. 最接近的三数之和 该算法通过排序和双指针技术,巧妙地在三数之和问题中寻找最接近目标值的组合,避免了暴力枚举的高时间复杂度。 阅读详情

题目

来源:LeetCode.

给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,
使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。

示例 1:

输入:nums = [-1,2,1,-4], target = 1
输出:2
解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2)

提示:

  • 3 < = n u m s . l e n g t h < = 1 0 3 3 <= nums.length <= 10^3 3<=nums.length<=103
  • − 1 0 3 < = n u m s [ i ] < = 1 0 3 -10^3 <= nums[i] <= 10^3 −103<=nums[i]<=103
  • − 1 0 4 < = t a r g e t < = 1 0 4 -10^4 <= target <= 10^4 −104<=target<=104

接下来看一下解题思路:

思路:排序 + 双指针:

这个题与三数之和非常类似,不同的是它需要找唯一一个答案,不是列举所有的,所以可以再之前的基础上适当的做一些优化。
    我们使用两层循环来枚举:

  • 假设数组的长度为 n n n,我们先枚举 a a a,它在数组中的位置为 i i i;
  • 为了防止重复枚举,我们在位置 [ i + 1 , n ) [i+1, n) [i+1,n) 的范围内枚举 b b b 和 c c c;

    我们使用双指针,用 p b p_b pb​ 和 p c p_c pc​ 分别表示指向 b b b 和 c c c 的指针,初始时, p b p_b pb​ 指向位置 i + 1 i+1 i+1,即左边界; p c p_c pc​ 指向位置 n − 1 n-1 n−1,即右边界。在每一步枚举的过程中,我们用 a + b + c a+b+c a+b+c 来更新答案,并且;

  • 如果 a + b + c ≥ target a+b+c \geq \textit{target} a+b+c≥target,那么就将 p c p_c pc​ 向左移动一个位置;
  • 如果 a + b + c < target a+b+c < \textit{target} a+b+c<target,那么就将 p b p_b pb​ 向右移动一个位置;
        实际上, p b p_b pb​ 和 p c p_c pc​ 就表示了我们当前可以选择的数的范围,而每一次枚举的过程中,我们尝试边界上的两个元素,根据它们与 target \textit{target} target 的值的关系,选择「抛弃」左边界的元素还是右边界的元素,从而减少了枚举的范围。这种思路与 LeetCode-11-盛最多水的容器. 中的双指针解法也是类似的。
        当我们枚举到恰好等于 target \textit{target} target 的 a + b + c a+b+c a+b+c 时,可以直接返回 target \textit{target} target 作为答案

    当我们枚举 a , b , c a, b, c a,b,c 中任意元素并移动指针时,可以直接将其移动到下一个与这次枚举到的不相同的元素,减少枚举的次数;

public static int threeSumClosest(int[] nums, int target) {
        int count = nums.length;
        // 确保 Math.abs(result - target) 绝对值最大
        int result = 10000000;
        Arrays.sort(nums);
        // 枚举 a
        for (int i = 0; i < count; ++i) {
            // 保证和上一次枚举的元素不相等
            if (i > 0 && nums[i] == nums[i - 1]) {
                continue;
            }
            // 使用双指针枚举 b 和 c
            int j = i + 1;
            int k = count - 1;
            while (k > j) {
                int sum = nums[i] + nums[j] + nums[k];
                // 如果和为 target 直接返回答案
                if (sum == target) {
                    return target;
                }
                // 根据差值的绝对值来更新答案
                if (Math.abs(sum - target) < Math.abs(result - target)) {
                    result = sum;
                }
                if (sum > target) {
                    // 如果和大于 target,移动 c 对应的指针
                    int k0 = k - 1;
                    // 移动到下一个不相等的元素
                    while (j < k0 && nums[k0] == nums[k]) {
                        --k0;
                    }
                    k = k0;
                } else {
                    // 如果和小于 target,移动 b 对应的指针
                    int j0 = j + 1;
                    // 移动到下一个不相等的元素
                    while (j0 < k && nums[j0] == nums[j]) {
                        ++j0;
                    }
                    j = j0;
                }
            }
        }
        return result;
}
总结

    时间复杂度 O ( N 2 ) O(N^2) O(N2),其中 N N N 是数组 nums \textit{nums} nums 的长度;
    空间复杂 O ( l o g N ) O(logN) O(logN),排序的空间复杂度为 O ( log ⁡ N ) O(\log N) O(logN)。然而我们使用了一个额外的数组存储了 nums \textit{nums} nums 的副本并进行排序,空间复杂度为 O ( N ) O(N) O(N);

【中等】力扣算法题解析LeetCode16:最接近的三数之和 给定一个整数数组和目标值,找出三个数的和最接近目标值的组合。通过排序和双指针法优化搜索过程:外层循环固定一个数,内层使用双指针寻找剩余两数。通过最小/最大和优化提前终止无效循环,跳过重复元素减少计算。时间复杂度O(n²),空间复杂度O(1)。Java实现中,排序后遍历数组,结合双指针和剪枝策略高效求解,确保返回唯一最接近的和。 阅读详情

相关推荐

当 AI + 可视化融入消防:开启智能消防新时代

总结来说,AI + 可视化技术融入消防,开启了智能消防新时代。它以精准预警、高效救援和全面资源管理,革新消防工作方式。从前期规划到系统搭建,再到后期运维,每个环节都为提升消防能力奠定基础。尽管面临技术成本、数据安全和人员适应等挑战,但随着技术发展和应用推广,这些问题将逐步解决。相信在 AI + 可视化助力下,消防领域将不断进步,为人们创造更安全生活环境,有效抵御火灾威胁。

2401_87844374的博客 1220

『力扣刷题』16_最接近的三数之和 解题代码

html: embed_local_images: true embed_svg: true offline: true toc: undefined print_background: false export_on_save: html: false date: 2019-12-01 updated: 2019-12-01 categories: 力扣刷题 title: 『力扣刷题』...

Paradox 382

MFC使用Websocket通讯介绍和实例(附完整源码)

踩坑点,下载了好几个boost版本编译,经常出问题,后来搜索了好久资料才发现如下评论:WebSocket++0.8.2 has been tested through Boost 1.72。WebSocketpp依赖于boost,因此在使用WebSocketpp前需要编译Boost;所以我们直接下载Boost 1.72的windows版的进行安装,安装完成还需要编译;WebSocketpp也叫WebSocket++;服务编译好之后,使用。

weixin_42530684的博客 1171

leetcode-16. 最接近的三数之和

通过排序加双指针法,我们能够高效地解决三数之和最接近(3Sum Closest)的问题。该方法利用数组的有序性,通过双指针在固定一个元素的基础上快速查找剩余两个元素,以找到最接近目标值的和。关键步骤回顾:排序数组,简化搜索过程。固定第一个元素,使用双指针查找剩余两个元素。在查找过程中持续更新最接近的和。合理移动指针以优化搜索效率。掌握此类技巧,不仅有助于解决类似的编程问题,还能加深对双指针法和排序在算法中的应用理解。

qq_39370495的博客 849

Fedora 41上安装钉钉7.6.25,我踩过的那些依赖坑和最终解决方案

本文详细记录了在Fedora 41上安装钉钉7.6.25版本的全过程,包括解决依赖问题、转换deb包为rpm格式、处理libm.so.6错误等关键步骤。通过分享这些实用技巧和最终解决方案,帮助Linux用户顺利在Fedora系统上运行钉钉客户端,提升工作效率。

weixin_30485379的博客 204

工业焊缝缺陷检测实战:我用PatchCore在自建数据集上踩过的那些坑

本文详细介绍了PatchCore算法在工业焊缝缺陷检测中的实战应用,包括数据准备、模型调参和阈值优化等关键环节。通过分析焊缝图像的特殊性和anomaly detection技术的优化策略,分享了在自建数据集上提升检测精度的实用经验,为工业质检领域提供有价值的参考方案。

weixin_42624889的博客 396

leetcode 16. 最接近的三数之和(C++)

leetcode 16. 最接近的三数之和(C++):

nanashi_F的博客 293

华为OD机试新系统真题【终端设备档位差异统计】

华为OD机试 新系统真题【终端设备档位差异统计】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【终端设备档位差异统计】多语言题解。

qq_45776114的博客 781

LeetCode16.最接近的三数之和 JavaScript

LeetCode16.最接近的三数之和 JavaScript 给定一个包括 n个整数的数组 nums 和 一个目标值target。找出nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 例如,给定数组 nums = [-1,2,1,-4], 和 target = 1. 与 target 最接近的三个数的和为 2. (-1 + 2 + 1 ...

weixin_34024034的博客 223

【异常】安装OpenClaw遇到 Windows环境pnpm安装node-llama-cpp postinstall生命周期脚本执行失败完整解决方案

摘要: Windows环境下使用pnpm安装node-llama-cpp时,postinstall脚本执行失败(错误码3221225477),主要因缺少C++编译工具链或预构建二进制下载失败。解决方案: 基础排查:确保管理员权限、Node.js ≥18、路径无中文; 安装编译工具:推荐Visual Studio的“C++桌面开发”组件或windows-build-tools; 环境变量配置:强制CPU模式+国内镜像(NODE_LLAMA_CPP_FORCE_CPU=true,镜像地址替换为国内源); pnp

奶爸的编程之路,也就一周冷个三天 617

【问题解决】解决 Python `PermissionError` 权限不足:文件/进程/端口全场景修复

本文总结了Python程序中常见的权限问题及解决方案,包括文件、进程和端口权限错误。文件权限问题通常由文件占用、权限不足或路径错误引起;进程问题多因权限不足或系统限制;端口问题则与端口占用、防火墙或特权端口相关。解决方案提供了详细的代码实现:文件权限管理器类(FilePermissionManager)包含检查权限(check_permission)、修复权限(fix_permission)、安全写入(safe_write)和安全删除(safe_delete)等方法,通过异常处理和临时文件等技术确保操作安全

博客 357

力扣(LeetCode 16)最接近的三数之和 python

题目 给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 例如,给定数组 nums = [-1,2,1,-4], 和 target = 1. 与 target 最接近的三个数的和为 2...

qq_41318002的博客 419

【即插即用模块】卷积篇 | CVPR 2025 | LSConv:大核捕全局,小核提速度,替换 3×3 卷积/自注意力,精度效率双飙升

文章摘要: LSConv是一种新型卷积模块,采用"大核感知+小核聚合"策略,在轻量级视觉任务中表现出色。该模块由两部分组成:7×7深度可分离卷积(LKP)捕捉全局信息,动态3×3卷积(SKA)实现高效特征聚合。相比传统卷积和自注意力机制,LSConv在降低计算量的同时提升了精度,尤其适合高分辨率视觉任务。实验表明,在轻量化模型中用LSConv替代3×3卷积或自注意力,可显著减少计算量并提高准确率。模块支持即插即用,提供Triton优化实现,可直接集成到现有卷积或Transformer架构

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1119

【LeetCode】16. 最接近的三数之和

这道题要求从数组中找出三个数,使其和最接近目标值。核心解法是排序+双指针:先排序数组,然后固定一个数,用双指针寻找另外两个数,计算三数之和与目标的差值,不断更新最接近值。时间复杂度为O(n²),空间复杂度O(1)。关键优化包括跳过重复元素和剪枝处理。该算法适用于数值逼近、优化问题等场景,是经典的双指针应用范例。

qq_32019341的博客 1040

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

LeetCode 16最接近的三数之和

LeetCode 16最接近的三数之和 题目简述:给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 nums = [-1, 2, 1, -4] target = 1 输出:2(-1+2+1=2) 思路一:暴力解法O(n3) 暴力三重循环枚举下标i,j,k,然后判断nums[i] + nums[j] + nums[k]是否与target更接近 class

XBlog 142

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

力扣LeetCode第16题最接近的三数之和

力扣LeetCode第16题最接近的三数之和

weixin_44061444的博客 544

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LeetCode第 16 题:最接近的三数之和(C++)

16. 最接近的三数之和 - 力扣(LeetCode) 假定每组输入只存在唯一答案。 有了上面的假定,可以知道数组中不存在重复元素,和上一题LeetCode第 15 题:三数之和(C++)很像,只是这题target不再固定为0,而且需要寻找最接近的。 不过思路都是一样的,排序之后固定第一个元素,然后使用双指针从两头往中间检索: class Solution { public: int threeSumClosest(vector<int>& nums, int target) {

zj 645

LeetCode16-最接近的三数之和

LeetCode16-最接近的三数之和 给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 例如,给定数组 nums = [-1,2,1,-4], 和 target = 1. 与 target 最接近的三个数的和为 2. (-1 + 2 + 1 = 2). 一、思...

lyd1995的博客 178

[leetcode_16_threeSumClosest] 力扣第16题 最接近的三数之和

力扣第16题 最接近的三数之和

C_0010的博客 933

力扣第16题:最接近的三数之和

学习目标: 力扣第16题:最接近的三数之和 学习内容: 给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 示例: 输入:nums = [-1,2,1,-4], target = 1 输出:2 解释:与 target 最接近的和是 2 (-1 + 2 + 1 = 2) 。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/probl

童一的博客 300

力扣LeetCode #16 最接近的三数之和(ThreeSumClosest)

- 题目描述 给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 提示: 3 <= nums.length <= 103 -103 <= nums[i] <= 103 -104 <= target <= 104 来源:LeetCode(https://leetcode-cn.com/problems/3sum-closest) - 示例

weixin_49155948的博客 289

#力扣 LeetCode16. 最接近的三数之和 @FDDLC

题目描述: 16. 最接近的三数之和 - 力扣(LeetCode) (leetcode-cn.com) 自测用例: [-1,2,1,-4] 1 [-1,2,1,-4] 2 [-1,2,1,-4] 3 [-1,2,1,-4] 4 [-1,2,1,-4] 5 [-1,2,1,-4] -7 Java代码一: class Solution { public int threeSumClosest(int[] a, int t) { int ans=a[0]+a[1]+

LiuXingchang的博客 319

力扣(LeetCode)16. 最接近的三数之和(C++)

【墨染】快排+双指针

墨染 337
上一篇: LeetCode-15-三数之和
下一篇: LeetCode-17-电话号码的字母组合
CodAlun
博客等级 码龄8年 46粉丝 96原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值