[LeetCode]167. Two Sum II - Input array is sorted

用 SAML 2.0 Bearer Assertion 配置 ABAP OAuth 2.0 令牌交换 摘要: SAP系统集成中,身份跨系统传递是关键挑战。OAuth 2.0的SAML 2.0 Bearer Assertion grant机制通过SAML断言换取访问令牌,实现安全身份传递。配置核心在ABAP的SOAUTH2事务码,需绑定可信SAML身份提供商(IdP)并指定访问范围。实际应用中,需确保SSL加密传输,正确配置SAML IdP信任关系,并为OAuth客户端分配专用系统用户。常见问题包括证书不匹配、权限配置不当等,需分层控制权限边界以保障安全。 阅读详情

[LeetCode]167. Two Sum II - Input array is sorted

题目描述

这里写图片描述

思路

开始的思路是暴力解,虽然用例都通过了,但是超时了
看了超时的用例,发现是太多重复造成的
于是加了重复检测的条件判断,提交通过之后发现速度太慢
换一种思路
两个指针从数组两边同时向中间移动,如果数字之和小于目标,则移动左指针,否则移动右指针

代码

注释部分为暴力解法

#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    /*
    vector<int> twoSum(vector<int>& numbers, int target) {
        int current, next;
        vector <int> res;
        bool finded = false;
        for (current = 0; current < numbers.size(); ++ current) {
            next = current + 1;

            finded = false;
            for (; next < numbers.size(); ++next) {
                if (numbers[current] + numbers[next] == target) {
                    finded = true;
                    res.push_back(current + 1);
                    res.push_back(next + 1);
                    break;
                }
            }

            if (finded)
                break;

            if (numbers[current] == numbers[next]) {
                ++current;
                continue;
            }
        }
        return res;
    }
    */
    vector<int> twoSum(vector<int>& numbers, int target) {
        int low = 0, high = numbers.size() - 1;
        vector<int> res;
        while (numbers[low] + numbers[high] != target) {
            if (numbers[low] + numbers[high] < target) {
                ++low;
            }
            else {
                --high;
            }
        }
        res.push_back(low + 1);
        res.push_back(high + 1);

        return res;
    }
};

int main() {
    vector<int> nums = { 0, 0, 3, 4 }, res;
    Solution s;
    res = s.twoSum(nums, 0);
    for (int p : res) {
        cout << p << " ";
    }
    system("pause");
}
大数据与宠物:健康监测数据分析 随着全球宠物市场规模的快速增长(2023年全球宠物产业规模已达3500亿美元),宠物健康管理需求呈现指数级上升。传统宠物医疗依赖定期体检和症状观察,存在滞后性和主观性缺陷。本文聚焦如何通过物联网(IoT)设备采集宠物生理数据(体温、心率、活动量等),利用大数据分析技术构建实时健康监测系统,实现宠物健康状态的动态评估、异常预警和疾病预测。研究范围涵盖数据采集技术、数据预处理方法、机器学习模型构建及实际应用场景落地。背景介绍:明确研究目的、目标读者及核心术语核心概念与联系。 阅读详情

相关推荐

unity打包流程整理-Windows/Mac/Linux平台

1.Platform(平台)功能: 选择目标构建的目标平台选项PC, Mac & Linux Standalone: 适用于 Windows、Mac 和 Linux 平台2.Target Platform(目标平台)功能: 选择具体的操作系统版本选项Windows: 针对 Windows 操作系统Mac: 针对 macOS 操作系统Linux: 针对 Linux 操作系统3.Architecture(架构)功能: 选择应用程序的目标处理器架构选项x86: 针对 32 位系统。

weixin_42333247的博客 5136

[LeetCode] 167. Two Sum II - Input array is sorted

原题链接: https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ 1. 题目描述 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific...

Ber03的博客 262

Aras Innovator系统配置-01对象类(一)

对象类配置-对象类属性说明

企业信息化(PLM,ERP.MES) 2032

LeetCode: 167. Two Sum II - Input array is sorted

LeetCode: 167. Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The

qha0731的专栏 312

LVDS高速ADC接口, xilinx fpga实现

FPGA实现lvds高速ADC数据接口,窗口对齐算法,Verilog源码

kuangxin的博客 6万+

基于STFT和卷积神经网络的时序数据分类

我们提供了相应的代码和数据,读者可以直接运行并尝试在自己的数据集上进行分类实验。在本文中,我们将介绍一种基于短时傅里叶变换(STFT)和卷积神经网络(CNN)的时序数据分类方法。我们将提供可直接运行的代码和数据,以帮助读者理解和实现这一方法。STFT可以提取信号的频谱信息,有助于捕捉时序数据中的关键特征。在这个例子中,我们将使用一个简化的手势识别数据集作为示例。在这段代码中,我们使用Adam优化器和稀疏分类交叉熵损失函数进行模型的编译。然后,我们使用训练集进行模型的训练,同时使用测试集进行模型性能的验证。

CodeWOW的博客 694

leetcode 167: Two Sum II - Input array is sorted

Two Sum II - Input array is sorted Total Accepted: 441 Total Submissions: 1017 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a

西施豆腐渣 9969

R语言做一个 GM (1,1)灰色预测模型

累加生成是GM(1,1)模型的另一个重要步骤,它通过构造累加生成序列,把非线性非平稳时间序列转化为线性平稳时间序列。GM(1,1)是一种基于灰色系统理论的预测模型,通常用于中小样本的非线性、非平稳时间序列数据分析。灰色预测模型的核心是灰度处理,将原始时间序列转化为灰色时间序列。这里使用R语言中的diff函数对时间序列进行一次差分,然后对结果取累加和得到灰度序列。以上是GM(1,1)灰色预测模型在R语言中的实现步骤。需要注意的是,GM(1,1)模型适用于中小样本的时间序列预测,对于长期预测效果可能较差。

Mrrunsen的博客 3842

【LeetCode】167. Two Sum II - Input array is sorted

我的个人微信公众号:Microstrong 微信公众号ID:MicrostrongAI 微信公众号介绍:Microstrong(小强)同学主要研究机器学习、深度学习、计算机视觉、智能对话系统相关内容,分享在学习过程中的读书笔记!期待您的关注,欢迎一起学习交流进步! 知乎主页:https://www.zhihu.com/people/MicrostrongAI/activities Github:https://github.com/Microstrong0305 个人博客:https://blo.

Microstrong 694

YOLOv8 PCB缺陷检测系统全流程实战:从开发到UI展示详解

毕设路上难免有波折,但只要跟着这个教程把“数据集处理、模型训练、UI开发”每一步都落实,你就已经超越了大多数同学。这个“PCB缺陷检测系统”既有技术深度(YOLOv8是工业级主流算法),又有工程价值(解决电子制造的实际痛点),还具备出色的可视化展示——这样的毕设,拿高分是水到渠成的事。

FJN110的博客 214

【用unity实现100个游戏之1】制作类元气骑士、挺进地牢——俯视角射击游戏多种射击效果(一)(附源码)

俯视角射击游戏)是一类以俯视视角进行游戏展示的射击游戏。在这种游戏中,玩家控制着一个角色或载具,从俯视的角度上方观察游戏世界,并与敌人进行战斗。这种视角使玩家能够有更好的全局观察和策略性,同时也强调快速反应和精确射击。视角:俯视角度可以是固定的,也可以随着玩家角色的移动而变化,但都允许玩家以全局视角观察整个战场,有利于制定战略和规划行动。射击:玩家通常需要使用各种武器来与敌人进行战斗,包括枪械、爆炸物等。射击动作依赖于玩家的反应速度和准确性。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 7833

LeetCode 167. Two Sum II - Input Array Is Sorted 题解

给你一个下标从 1 开始的整数数组 ,该数组已按 非递减顺序排列,请你从数组中找出满足相加之和等于目标数 的两个数。如果设这两个数分别是 和 ,则 。以长度为 2 的整数数组 的形式返回这两个整数的下标 和 。你可以假设每个输入 只对应唯一的答案,而且你 不可以 重复使用相同的元素。你所设计的解决方案必须只使用常量级的额外空间。示例 1: 示例 2: 示例 3: 解题思路 方法:双指针 思路:复杂度分析: 测试用例 测试用例 1: 输入:输出:输入:输出:输入:输出:本题是双指针的经典应用问题,主要

cannonjinx的博客 2463

【IoT】 产品设计之结构设计:如何设计产品按键

1、硅胶按键功能实现有两种接触方式 1)硅胶按键按压在DOME片(锅仔片)上 通常用在手机、儿童手表手机、防水手机等防水设备上。 2)硅胶按键增加导电基,一种黑色的导电碳粒,实现回路导电 通常用在遥控器、电脑键盘、特殊设备上。 两种方式结构设计原理是一样的,按键的固定与配合间隙与行程要确保好。 2、硅胶遥控器按键的结构方式(导电基) 按键帽为大颗粒实心的,触点为黑色导电基,通过压注成型融合为一体,那么这种按键结构设计时需要注意那些呢? 最主要的是按键按压回弹的手感,由于没有DOME片实现

产品线负责人 8670

Leetcode: 167. Two Sum II - Input array is sorted

Leetcode: 167. Two Sum II - Input array is sorted 超时的代码: public class Sum22 { public int[] twoSum(int[] numbers, int target) { int result[] = new int[2]; ...

哎呀妈呀脑壳疼脑壳疼 98

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

[python]LeetCode_167. Two Sum II - Input Array Is Sorted

[python]LeetCode_167. Two Sum II - Input Array Is Sorted 文章目录[python]LeetCode_167. Two Sum II - Input Array Is Sorted牽涉概念及時間紀錄一、題目內容二、想法思路1.直觀想法:2.想想發現不太對,優化一下:总结 牽涉概念及時間紀錄 20220408 17:08-17:20 for 第一次 使用雙指針方式能降低時間複雜度 當需要雙迴圈時可以往此方向考慮 一、題目內容 簡而言之: 就是給定一個

weixin_44582732的博客 876

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Leetcode 167 Two Sum II - Input array is sorted

Leetcode 167 Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function tw...

fengran_mark的博客 114

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Leetcode 167. Two Sum II - Input array is sorted

Leetcode 167. Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function ...

weixin_43332727的博客 187

LeetCode力扣 167. 两数之和 II - 输入有序数组 Two Sum II - Input array is sorted 题解代码 JavaScript

问题https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/ 练习使用JavaScript解答 /** * @param {number[]} numbers * @param {number} target * @return {number[]} */ var twoSum = function(numbers, target) { var i = 0, j = numbers.length-1; .

Coding home - 漂流瓶jz 602

LeetCode 167. Two Sum II - Input array is sorted (Java版; Easy)

welcome to my blog LeetCode 167. Two Sum II - Input array is sorted (Java版; Easy) 题目描述 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a...

littlehaes的博客 299

leetcode Python 167. Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two number

qq_32611349的博客 399

Java [Leetcode 167]Two Sum II - Input array is sorted

题目描述: Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the ...

dkk37351的博客 210

LeetCode 167.Two Sum II - Input array is sorted【Java】

题目描述 167. 两数之和 II - 输入有序数组 AC代码 class Solution { public int[] twoSum(int[] numbers, int target) { int[] res=new int[2]; int i=0,j=numbers.length-1; while(i<numbers.lengt...

NayelyA的博客 261

LeetCode167: Two Sum II - Input array is sorted

题目链接:Two Sum II - Input array is sorted 1. Description Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The...

暮日落流年的博客 239

LeetCode 167——Two Sum II - Input array is sorted

Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers ...

CrazyOnes的博客 355

LeetCode 167. Two Sum II - Input array is sorted

LeetCode 167. Two Sum II - Input array is sorted 问题来源LeetCode 167. Two Sum II - Input array is sorted 问题描述 Given an array of integers that is already sorted in ascending order, find two numbers suc

yanqinghe123的专栏 299

【leetcode】167. Two Sum II - Input array is sorted

167.Two Sum II - Input array is sorted Given an array of integers that is alreadysorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum ...

lemonade13的博客 107
上一篇: 感知机(笔记提纲)
下一篇: [LeetCode]506. Relative Ranks
charon____
博客等级 码龄11年 3粉丝 202原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值