Grace
grace's dev_note
Grace
전체 방문자
오늘
어제
  • 분류 전체보기
    • FrontEnd
      • Next.js
      • React
      • ReactNativ..
      • Vue
    • Javascript
      • 러닝 자바스크립트
      • 모던 자바스크립트
    • CS
    • DataScienc..
      • Data Struc..
      • LeetCode
    • BackEnd
      • Express
      • Node.js
      • Nest.js
    • DevOps
      • Docker
    • 매일메일
    • 회고
    • 코드캠프

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • vue-query
  • node.js
  • Express
  • 자바스크립트
  • Vue
  • Vue3
  • Vue.js
  • React Native
  • 함수
  • 알고리즘
  • tanstack
  • nest.js
  • postgres
  • Vite
  • 번들러
  • vitejs
  • pinia
  • PostgreSQL
  • backend
  • javascript

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Grace

grace's dev_note

DataScience/LeetCode

[Easy] Two Sum

2022. 10. 6. 09:17

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.

Example 1:

Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

Example 2:

Input: nums = [3,2,4], target = 6
Output: [1,2]

Example 3:

Input: nums = [3,3], target = 6
Output: [0,1]

Constraints:

  • 2 <= nums.length <= 104
  • 109 <= nums[i] <= 109
  • 109 <= target <= 109
  • Only one valid answer exists.
function(nums, target) {
    for(let i=0; i<nums.length; i++){
        for(let j=0; j<nums.length; j++){
            if(i===j) continue;
            if(nums[i]+nums[j] === target) return [i, j]
        }
    }
};
저작자표시 비영리 변경금지 (새창열림)

'DataScience > LeetCode' 카테고리의 다른 글

[Easy] Sqrt(x)  (0) 2022.11.17
[Easy] Plus One  (0) 2022.11.16
[Easy] Valid Parentheses  (0) 2022.11.02
[Easy] Roman to Integer  (0) 2022.10.12
[Easy] Palindrome Number  (0) 2022.10.11
    'DataScience/LeetCode' 카테고리의 다른 글
    • [Easy] Plus One
    • [Easy] Valid Parentheses
    • [Easy] Roman to Integer
    • [Easy] Palindrome Number
    Grace
    Grace
    기술 및 회고 블로그

    티스토리툴바