File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @description nums ๋ฐฐ์ด์์ ์ค๋ณต ์ซ์ ํ์ธ
3+ * @param nums - ์ซ์ ๋ฐฐ์ด
4+ * @returns boolean - ์ค๋ณต ์ซ์ ์ฌ๋ถ
5+ */
6+ const containsDuplicate = ( nums : number [ ] ) => {
7+ const hasSeen = new Set < number > ( ) ;
8+
9+ for ( const num of nums ) {
10+ if ( hasSeen . has ( num ) ) {
11+ return true ;
12+ }
13+ hasSeen . add ( num ) ;
14+ }
15+ return false ;
16+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @description nums ๋ฐฐ์ด์์ ๋ ์๋ฅผ ๋ํด target์ ๋ง์กฑํ๋ ์ธ๋ฑ์ค๋ฅผ ๋ฐํ
3+ * @param {number[] } nums - ์ซ์ ๋ฐฐ์ด
4+ * @param {number } target - ๋ชฉํ ์ซ์
5+ * @return {number[] } - ๋ ์์ ์ธ๋ฑ์ค
6+ */
7+ var twoSum = function ( nums , target ) {
8+ const map = new Map ( ) ;
9+
10+ for ( let i = 0 ; i < nums . length ; i ++ ) {
11+ const current = nums [ i ] ;
12+ const needed = target - current ;
13+ if ( map . has ( needed ) ) {
14+ return [ map . get ( needed ) , i ] ;
15+ }
16+ map . set ( current , i ) ;
17+ }
18+ } ;
You canโt perform that action at this time.
0 commit comments