File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ var missingNumber = function ( nums ) {
6+ nums = nums . sort ( ) ;
7+
8+ for ( let i = 0 ; i < nums . length ; i ++ ) {
9+ if ( nums [ i ] !== i ) return i ;
10+ }
11+
12+ return nums . length ;
13+ } ;
14+
15+ // TC
16+ // nums ์ ๋ ฌ์ ํ๊ธฐ ์ํด์ ์ํ (๊ธธ์ด n) -> ์ต์ ์ ๊ฒฝ์ฐ O(n) ์ด์ง๋ง, ํ๊ท ์ ์ผ๋ก O(n log n)
17+ // ๋น ์ง ์ซ์๋ฅผ ์ฐพ๊ธฐ์ํด์ ์ํ (์ต๋๊ธธ์ด n)
18+ // ๋ฐ๋ผ์ ์๊ฐ ๋ณต์ก๋๋ ์ต๋ O(n log n)
19+
20+ // SC
21+ // ๊ธธ์ด๊ฐ n์ธ ๋ฐฐ์ด์ ์ ์ฅํ ๊ณต๊ฐ ํ์
22+ // O(n)
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } s
3+ * @return {boolean }
4+ */
5+ var isPalindrome = function ( s ) {
6+
7+ let str = normalize ( s ) ;
8+ let reverseStr = "" ;
9+
10+ function normalize ( str ) {
11+ str = str . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, "" ) ;
12+
13+ return str ;
14+ }
15+
16+
17+ for ( let i = str . length - 1 ; i >= 0 ; i -- ) {
18+ reverseStr += str [ i ] ;
19+ } ;
20+
21+
22+ return str === reverseStr ;
23+ } ;
24+
25+ // TC : O(n)
26+ // normalize ํจ์์์ n๋ฒ(s์๊ธธ์ด) ์ํ(toLowerCase) + n๋ฒ ์ํ(replace)
27+ // reverseStr ์ ๋ง๋ค๊ธฐ ์ํด์ for๋ฌธ - ๊ธธ์ด n
28+ // = O(3n) ๋ฐ๋ผ์ O(n)
29+
30+ // SC : O(n)
31+ // ๋ณ์ str , reversStr ๋ชจ๋ ๊ธธ์ด๊ฐ n ์ด๋ฏ๋ก O(n)
You canโt perform that action at this time.
0 commit comments