当前位置:网站首页>Leetcode skimming ---1
Leetcode skimming ---1
2022-07-03 10:35:00 【Long time no see 0327】
subject : Given an array of integers nums And an integer target value target, Find and in the array as the target value target the Two integers , And return their array subscripts . It can be assumed that each input will correspond to only one answer . however , The same element in the array cannot be repeated in the answer . Answers can be returned in any order .
Input :nums = [2,7,11,15], target = 9
Output :[0,1]
Method 1 : Hashtable
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
unordered_map<int, int> hashtable;
for (int i = 0; i < nums.size(); ++i) {
auto it = hashtable.find(target - nums[i]);
if (it != hashtable.end()) {
return {it -> second, i};
}
hashtable[nums[i]] = i;
}
return {};
}
};Complexity analysis
Time complexity :O(N)
Spatial complexity :O(N)
边栏推荐
- Notes - regular expressions
- Multilayer perceptron (pytorch)
- 7、 Data definition language of MySQL (2)
- 神经网络入门之矩阵计算(Pytorch)
- Leetcode刷题---189
- Out of the box high color background system
- 【SQL】一篇带你掌握SQL数据库的查询与修改相关操作
- Simple real-time gesture recognition based on OpenCV (including code)
- Raspberry pie 4B deploys lnmp+tor and builds a website on dark web
- [LZY learning notes -dive into deep learning] math preparation 2.1-2.4
猜你喜欢

Tensorflow—Neural Style Transfer

Tensorflow - tensorflow Foundation

I really want to be a girl. The first step of programming is to wear women's clothes

ECMAScript -- "ES6 syntax specification # Day1

Label Semantic Aware Pre-training for Few-shot Text Classification

A complete answer sheet recognition system

Introduction to deep learning linear algebra (pytorch)

Preliminary knowledge of Neural Network Introduction (pytorch)

LeetCode - 715. Range module (TreeSet)*****

Leetcode刷题---367
随机推荐
[C question set] of Ⅵ
20220610 other: Task Scheduler
Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported
【毕业季】图匮于丰,防俭于逸;治不忘乱,安不忘危。
Ind yff first week
安装yolov3(Anaconda)
Ind wks first week
EFFICIENT PROBABILISTIC LOGIC REASONING WITH GRAPH NEURAL NETWORKS
Leetcode-100: same tree
Neural Network Fundamentals (1)
Model evaluation and selection
Label Semantic Aware Pre-training for Few-shot Text Classification
Tensorflow - tensorflow Foundation
High imitation bosom friend manke comic app
Leetcode刷题---704
Ind kwf first week
Raspberry pie 4B installs yolov5 to achieve real-time target detection
Hands on deep learning pytorch version exercise solution - 2.5 automatic differentiation
神经网络入门之预备知识(PyTorch)
Ut2017 learning notes