当前位置:网站首页>Leetcode horloge quotidienne - 1. Somme des deux nombres
Leetcode horloge quotidienne - 1. Somme des deux nombres
2021-10-14 04:09:01 【Sun zhongming】
1. Somme des deux nombres
C'est facile.11915Le partage des collections passe à l'anglais pour recevoir des commentaires dynamiques
Donner un tableau entier nums
Et une valeur cible entière target
,Veuillez trouver dans ce tableau Et pour les valeurs cibles target
Celui - là. Deux. Entier,Et renvoie leurs indices de tableau.
Vous pouvez supposer que chaque entrée ne correspond qu'à une seule réponse.Mais,Le même élément du tableau ne peut pas être répété dans la réponse.
Vous pouvez retourner les réponses dans n'importe quel ordre.
Exemple 1:
Entrée:nums = [2,7,11,15], target = 9
Produits:[0,1]
Explication:Parce que nums[0] + nums[1] == 9 ,Retour [0, 1] .
Exemple 2:
Entrée:nums = [3,2,4], target = 6
Produits:[1,2]
Exemple 3:
Entrée:nums = [3,3], target = 6
Produits:[0,1]
Conseils:
2 <= nums.length <= 104
-109 <= nums[i] <= 109
-109 <= target <= 109
- Il n'y aura qu'une seule réponse valide
**Niveau avancé:**Vous pouvez penser à une complexité temporelle inférieure à O(n2)
L'algorithme de?
class Solution {
// Violence
public int[] twoSum(int[] nums, int target) {
int[] res = new int[2];
int len=nums.length;
for(int i=0;i<=len-1;i++){
for(int j=i+1;j<=len-1;j++){
if(nums[i]+nums[j]==target){
res[0]=i;
res[1]=j;
return res;
}
}
}
return res;
}
}
/** * Encore une foishash Tempso(n) Espaceo(n) */
import java.util.Map;
import java.util.HashMap;
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer,Integer> map =new HashMap<Integer,Integer>();
int len=nums.length;
for(int i=0;i<=len-1;i++){
if(map.containsKey(target-nums[i])){
return new int[]{
map.get(target-nums[i]),i};
}
map.put(nums[i],i);
}
return null;
}
}
版权声明
本文为[Sun zhongming]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/10/20211013211945163p.html
边栏推荐
- Can Laobaigan liquor stock still rise? Is Laobaigan wine worth long-term investment
- How about rely on smart phone stock? Thousands of shares and thousands of comments of rely on smart electronics
- Is Fangda carbon stock worth holding for a long time? Future market trend of Fangda carbon stock
- Can green water source stocks be held for a long time? Why don't blue water stocks rise
- 腦機接口數據分析工具EEGLAB01---安裝eeglab
- 解决:【安全警報】該站點安全證書的吊銷信息不可用,是否繼續?
- Outil d'analyse des données de l'interface cerveau - ordinateur eeglab01 - - - installation eeglab
- Résolution: [alerte de sécurité] l'information sur la révocation du certificat de sécurité de ce site n'est pas disponible. Voulez - vous continuer?
- Aucun protocole TCP disponible dans l'espace tampon ne peut libérer le problème
- Le bon Code est géré - - construire un serveur ci en utilisant Jenkins
猜你喜欢
-
Projet d'équipe (1) (équipe chauve de Jiangshan Dai Youcai)
-
Ruby 's Adventure: 2D Beginner I, Unity Starting
-
17 novembre 2020
-
Will Yonghe Zhikong stock rise? Analysis on stock value of Yonghe intelligent control
-
Is Yingjia gongjiu stock suitable for long-term holding? Thousands of shares and thousands of comments on Yingjia gongjiu stock
-
How about Xingwang Ruijie stock? STARNet Ruijie stock thousands of shares and thousands of comments
-
Why did Tianqi lithium's stock soar recently? Thousands of shares and thousands of comments of Tianqi lithium
-
Can Guangsheng nonferrous metals stock be held for a long time? Guangsheng Nonferrous Metals Co., Ltd
-
How about Yunhai metal stock? Yunhai metal stock thousand shares thousand comments
-
Why doesn't TCL technology stock rise? Reasons for TCL technology stocks falling every day
随机推荐
- What are the good low-cost stocks at present? Potential stocks below 3 yuan
- High quality low price stocks currently at the bottom (list of high quality low price stocks below RMB 10)
- 10 bull stocks with the largest increase in 2021 (demon stocks with a 10 fold increase this year)
- How about Huayin power stock? Will Huayin power stock rise
- Can Luzhou Laojiao stock still be bought? Luzhou Laojiao stock evaluation
- Is Datang Power Generation stock worth holding for a long time? Why does Datang Power Generation stock not rise for ten years
- What does BAIC Blue Valley do? Does BAIC Blue Valley stock have potential
- Principes de la plate - forme de développement Android, questions d'entrevue de développement Android
- Machine level representation of data
- No buffer space available tcp協議無法釋放問題
- 好代碼是管出來的——使用Jenkins搭建CI服務器
- Quelle est la différence entre l'analyse des données et l'exploration des données?
- HTB Jerry
- Detailed explanation of real-time cloud rendering technology - principle, application and advantages
- Original code complement
- Cs8406 cirrus logic up to 192 kHz frame rate
- Générateur de code général de luminosité HD CG
- LeetCode 47. 全排列 II
- 明明很努力的写博客,为啥没人看?试试这些方法和工具(建议收藏)
- 【微信小程序爬虫】表情包小程序图文视频教学,从零写起,保姆教程!!!
- 【微信小程序爬蟲】錶情包小程序圖文視頻教學,從零寫起,保姆教程!!!
- 【 Wechat applet crawler】 emotion Pack applet picture and Text Video Teaching, Write from zero, Nursing tutorial!!!
- Pourquoi personne ne lit un blog?Essayez ces méthodes et outils (Collection recommandée)
- Leetcode 47. Full arrangement II
- Analyse de l'architecture Sonic
- Product power continues to evolve, and the sales volume of Changan Ford increased month on month in September
- More worrying than the safety of power batteries is the shortage of lithium resources
- Jenkins est trop con?Essayez ces alternatives, l'encens voleur!
- Pression artérielle normale (yzoj - 1078)
- Trouver un nombre naturel spécial (yzoj - 1079)
- Nombre de statistiques à 4 chiffres satisfaisant aux conditions (yzoj - 1080)
- Somme des séries (yzoj - 1081)
- Jingjing à rendez - vous (yzoj - 1040)
- Trouver le plus grand diviseur commun des nombres n (yzoj - 1059)
- Imprimer le triangle numérique (yzoj - 1068)
- Mercenaires (yzoj - 1089)
- Calculer la fonction dérivée du polynôme (yzoj - 1090)
- Nombre indépendant de 7 (yzoj - 1091)
- Statistiques (yzoj - 1092)
- Dessiner un rectangle (yzoj - 1093)