1.数组的长度 length()

.容器vector长度  size()

.容器vector

vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库。
vector之所以被认为是一个容器,是因为它能够像容器一样存放各种类型的对象,
简单地说,vector是一个能够存放任意类型的动态数组,能够增加和压缩数据。

在vector中放入数据:c.push_back(elem)  // 在尾部加入一个数据。

 class Solution
{
public:
vector<int> twoSum(vector<int>& nums, int target)
{ //vector 型
int n = nums.size(); // 求其长度
vector<int> result;
int i = ;
for (i = ; i < n ;i++)
{
for (int j = i+ ; j < n ;j++)
{
if (nums[i]+nums[j] == target)
{
result.push_back(i);
result.push_back(j);
return result;
}
}
}
return {}; //返回空了吧。。。
}
};

leetcode 之 two sum (easy)c++的更多相关文章

  1. 【leetcode】Two Sum (easy)

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  2. [leetcode] #112 Path Sum (easy)

    原题链接 题意: 给定一个值,求出从树顶到某个叶(没有子节点)有没有一条路径等于该值. 思路: DFS Runtime: 4 ms, faster than 100.00% of C++ class ...

  3. [LeetCode] 437. Path Sum III_ Easy tag: DFS

    You are given a binary tree in which each node contains an integer value. Find the number of paths t ...

  4. [LeetCode] #1# Two Sum : 数组/哈希表/二分查找/双指针

    一. 题目 1. Two SumTotal Accepted: 241484 Total Submissions: 1005339 Difficulty: Easy Given an array of ...

  5. [array] leetcode - 53. Maximum Subarray - Easy

    leetcode - 53. Maximum Subarray - Easy descrition Find the contiguous subarray within an array (cont ...

  6. LeetCode算法题-Sum of Left Leaves(Java实现)

    这是悦乐书的第217次更新,第230篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第85题(顺位题号是404).找到给定二叉树中所有左叶的总和.例如: 二叉树中有两个左叶 ...

  7. LeetCode算法题-Sum of Two Integers(Java实现)

    这是悦乐书的第210次更新,第222篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第78题(顺位题号是371).计算两个整数a和b的总和,但不允许使用运算符+和 - .例 ...

  8. LeetCode--Array--Two sum (Easy)

    1.Two sum (Easy)# Given an array of integers, return indices of the two numbers such that they add u ...

  9. Java for LeetCode 216 Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  10. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

随机推荐

  1. JS高级

    一.函数高级 1.函数回调 函数回调的本质:在一个函数中,满足特定条件下,调用另一个函数 // 回调的函数 function callback(data) {} // 逻辑函数 function fu ...

  2. 文本框监听事件blur()的简单使用

    场景描述:在做编辑功能的时候,经常要判断编码,或者密码之类的是否已经被使用,以前自己做的时候,经常都是在提交了之后才判断的,到现在,才发现,这样做的用户体验不好,完美一点的做法就是当此文本框失去焦点的 ...

  3. Python学习笔记五

    一. 递归 递归函数: def a (): print ("from b") b() def b(): print("from a ") a() a() 递推和 ...

  4. Jmeter性能测试之Monitor监控(四)

    使用Jmeter(该篇文章使用的版本最高为3.1, 3.1+的版本存在兼容性问题)做性能测试, 要监控服务器硬件资源消耗情况, 可以使用扩展插件完成. 1. 服务端插件下载agent, 点击这里 , ...

  5. Storm介绍及安装部署

    本节内容: Apache Storm是什么 Apache Storm核心概念 Storm原理架构 Storm集群安装部署 启动storm ui.Nimbus和Supervisor 一.Apache S ...

  6. Java Spring Boot VS .NetCore (十) Java Interceptor vs .NetCore Interceptor

    Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filter Jav ...

  7. python---循环双向链表实现

    这个方案里的尾插入,就使用了更高效的prev指标. 但感觉remove的代码不够和前面统一, 我有代码洁癖了???? # coding = utf-8 # 双向链表 class Node: # 双向链 ...

  8. Nginx 和 IIS 实现动静分离(转)

    转载地址:https://www.cnblogs.com/paul8339/p/5825201.html 动静分离,说白了,就是将网站静态资源(HTML,JavaScript,CSS,img等文件)与 ...

  9. 【Java】 剑指offer(30) 包含min函数的栈

    本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集   题目 定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的min ...

  10. NEO GUI 多方签名使用

    众所周至,NEOGUI是一个开发者演示用钱包,使用体验是非常的不友好的. 今天本来打算使用多方签名账户,发现和想象的不一样,请教了小伙伴也不行.遂调试了一下原因,发现踩进坑里了.     把这个问题记 ...