Two Sum
来源:互联网 发布:java开源oa系统源码 编辑:程序博客网 时间:2024/06/05 15:29
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].
class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { int count = nums.size(); for(int i=0;i<count-1;i++){for(int j=i+1;j<count;j++){if(nums[i] + nums[j] == target){ vector<int>ivec1{i,j}; return ivec1; } } } }};
阅读全文
0 0
- Two Sum
- Two Sum
- Two Sum
- two sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- Two Sum
- 581. Shortest Unsorted Continuous Subarray
- 嵌入式linux平台设备驱动(设备驱动模型)开发之linux内核中bus总线
- 第一个网络程序---hostent
- Python简单通信录程序
- 基础知识复习笔记 Day 1
- Two Sum
- 学习网站
- tarjan中的玄学
- windows下cuda7.5卸载方法
- 数据通信网的交换方式
- linux之sed
- cache-缓存和memory-内存
- 如何在PowerDesigner中给一主键设置自增
- JDBC连接MySQL数据库实现宠物领养案例