File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @param {number } target
4
+ * @return {number[] }
5
+ */
6
+
7
+ /*
8
+ ๋ ์ ๋ํ๊ธฐ
9
+ nums: ์ซ์ ๋ฐฐ์ด
10
+ target: ๋ชฉํ ์ซ์
11
+
12
+ target ์ซ์์ ๋ง๊ฒ nums ๋ฐฐ์ด์ค 2๊ฐ๋ฅผ ๋ํจ.
13
+ return์ ๋ํ ๋ ์์ index
14
+ - for i in nums -> target - i ๊ฐ์ด ๋ฐฐ์ด๋ด์ ์๋์ง ์ฐพ๊ธฐ
15
+ */
16
+ var twoSum = function ( nums , target ) {
17
+ let indexArray = [ ] ; // ๋ต์ ์ ์ฅํ ๋ฐฐ์ด
18
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
19
+ let tNum = nums . lastIndexOf ( target - nums [ i ] ) ; // ๋ฐฐ์ด๋ด์ target - nums[i] ์ฐพ๊ธฐ
20
+ if ( i === tNum ) { // ๊ฐ์ ์ ์ฌ์ฉ ๋ฐฉ์ง
21
+
22
+ }
23
+ else if ( tNum > 0 && indexArray . lastIndexOf ( i ) === - 1 ) { // ๋ฐฐ์ด๋ด์ ์ํ๋ ๊ฐ์ด ์๋ค๋ฉด
24
+ indexArray . push ( i ) ;
25
+ indexArray . push ( tNum ) ;
26
+ break ;
27
+ }
28
+ }
29
+ return indexArray ;
30
+ } ;
You canโt perform that action at this time.
0 commit comments