TwoSum

samuel Jo·2022년 11월 23일
0

codewars

목록 보기
5/46

Write a function that takes an array of numbers(integers for the tests) and a target number.It should find two different items in the array that, when added together, give the target value.The indices of these items should then be returned in a tuple / list(depending on your language) like so: (index1, index2).

For the purposes of this kata, some tests may have multiple answers; any valid solutions will be accepted.

The input will always be valid(numbers will be an array of length 2 or greater, and all of the items will be numbers; target will always be the sum of two different items from that array).

how it works ==>Based on: http://oj.leetcode.com/problems/two-sum/

오늘의 codewars 문제

이중포문 사용.
다른 풀이를 보니까 map을 이용해서 푼 코드가 있어서 읽어보고 작성해봤다.

이중포문사용시

map을 사용하면

런타임걸리는시간 - 이중포문 > map
메모리사용량 - 이중포문 < map

리트코드도 애용해보려고 노력해봐야겠다.메모리사용량과 런타임시간 포진도를 볼 수 있어서 좋은듯..?

profile
step by step

0개의 댓글