当前位置:网站首页>return new int[]{i + 1, mid + 1}; return {i + 1, mid + 1};
return new int[]{i + 1, mid + 1}; return {i + 1, mid + 1};
2022-06-28 19:34:00 【Old mark】
leetcode167. Sum of two numbers II - Input an ordered array 
java return
It is equivalent to returning after declaration
Return string return new String(s);
Returns an array of return new int[]{-1, -1};
C++
return {low + 1, high + 1};
It should also return an array
class Solution {
public int[] twoSum(int[] numbers, int target) {
int low = 0, high = numbers.length - 1;
while (low < high) {
int sum = numbers[low] + numbers[high];
if (sum == target) {
return new int[]{
low + 1, high + 1};
} else if (sum < target) {
++low;
} else {
--high;
}
}
return new int[]{
-1, -1};
}
}
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
int low = 0, high = numbers.size() - 1;
while (low < high) {
int sum = numbers[low] + numbers[high];
if (sum == target) {
return {
low + 1, high + 1};
} else if (sum < target) {
++low;
} else {
--high;
}
}
return {
-1, -1};
}
};
边栏推荐
- How to learn JS through w3school / how to use the JS reference manual of w3school
- Bayesian inference problem, MCMC and variational inference
- How does redis implement inventory deduction? How to prevent oversold?
- Grafana draws the trend chart
- Live app system source code, automatically playing when encountering video dynamically
- Ffmpeg learning summary
- Show the actual work case of creating intermediate data table with SQL
- Upward and downward transformation
- How to remove dataframe field column names
- Paper notes: universal value function approvers
猜你喜欢

Build halo blog in arm version rk3399

智能计算系统1 环境搭建

机器学习笔记 temperature+Softmax

new String(“hello“)之后,到底创建了几个对象?

视差js特效js轮播图插件

Tencent tangdaosheng: facing the new world of digital and real integration, developers are the most important "architects"

秋招经验分享 | 银行笔面试该怎么准备

From design delivery to development, it is easy and efficient!

Leetcode 周赛299

严重性 代码 说明 项目 文件 行 禁止显示状态 错误 C1047 对象或库文件“.lib”是使用与其他对象(如“x64\Release\main.obj”)不同的
随机推荐
Kaggle gastrointestinal image segmentation competition baseline
From design delivery to development, it is easy and efficient!
华为云OneMeeting告诉你全场景会议这么开!
春风动力携手华为打造智慧园区标杆,未来工厂创新迈上新台阶
判断字符串是否为空
Demo of integrated development of intelligent computing system 3 plugin
Markdown绘图mermaid实用教程
JVM memory structure
智能计算系统1 环境搭建
Double contextual relationship network for polyp segmentation
类加载机制与对象的创建
Grafana draws the trend chart
数论 --- 欧拉函数、筛法求欧拉函数、欧拉定理、费马小定理详细证明
国内有正规安全的外汇交易商吗?
The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
Variable autoencoders (vaes)
Machine learning notes temperature+softmax
颜色渐变的FontAwesome图标
C#连接数据库完成增删改查操作
深度学习需要多强的数学基础?