File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
longest-repeating-character-replacement Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ * @param {string } s
4+ * @param {number } k
5+ * @return {number }
6+ */
7+ var characterReplacement = function ( s , k ) {
8+ let start = 0 ;
9+ let maxLength = 0 ;
10+ let maxCharCount = 0 ;
11+ let count = { } ;
12+
13+ for ( let end = 0 ; end < s . length ; end ++ ) {
14+ const char = s [ end ] ;
15+ count [ char ] = ( count [ char ] || 0 ) + 1 ;
16+
17+ // ํ์ฌ ์๋์ฐ ์์์ ๊ฐ์ฅ ๋ง์ด ๋์จ ๋ฌธ์ ์ ๊ฐฑ์
18+ maxCharCount = Math . max ( maxCharCount , count [ char ] ) ;
19+
20+ // ๋ฐ๊ฟ์ผ ํ๋ ๋ฌธ์ ์๊ฐ k๋ณด๋ค ๋ง์ผ๋ฉด โ ์ผ์ชฝ ํฌ์ธํฐ ์ด๋
21+ if ( end - start + 1 - maxCharCount > k ) {
22+ count [ s [ start ] ] -- ;
23+ start ++ ;
24+ }
25+
26+ // ํ์ฌ ์๋์ฐ ๊ธธ์ด๋ก ์ต๋ ๊ธธ์ด ๊ฐฑ์
27+ maxLength = Math . max ( maxLength , end - start + 1 ) ;
28+ }
29+
30+ return maxLength ;
31+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * https://leetcode.com/problems/reverse-bits/
3+ * @param {number } n - a positive integer
4+ * @return {number } - a positive integer
5+ */
6+ var reverseBits = function ( n ) {
7+ let result = 0 ;
8+
9+ for ( let i = 0 ; i < 32 ; i ++ ) {
10+ // result๋ฅผ ์ผ์ชฝ์ผ๋ก 1์นธ ๋ฐ๊ธฐ
11+ result <<= 1 ;
12+
13+ // n์ ๋ง์ง๋ง ๋นํธ๋ฅผ result์ ์ค๋ฅธ์ชฝ ๋์ ์ถ๊ฐ
14+ result |= n & 1 ;
15+
16+ // n์ ์ค๋ฅธ์ชฝ์ผ๋ก 1์นธ ๋ฐ๊ธฐ
17+ n >>>= 1 ;
18+ }
19+
20+ // >>> 0์ ํ๋ฉด ๋ถํธ ์๋ 32๋นํธ ์ ์๋ก ๋ฐํ๋จ
21+ return result >>> 0 ;
22+ } ;
Original file line number Diff line number Diff line change @@ -34,4 +34,19 @@ var reverseList = function (head) {
3434reverseList(head)์์ head๋ ๋ฆฌ์คํธ ์ ์ฒด์ ์ง์
์ .
3535head ํ๋๋ง ์๊ณ ์์ด๋, .next๋ฅผ ๋ฐ๋ผ๊ฐ๋ฉด์ ์ ์ฒด ๋
ธ๋๋ค์ ์์ฐจ์ ์ผ๋ก ์ ๊ทผํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ฆฌ์คํธ ์ ์ฒด๋ฅผ ๋ค๋ฃฐ ์ ์์
3636
37+ // ๋
ธ๋ ๊ตฌ์กฐ ์ ์
38+ function ListNode(val, next = null) {
39+ this.val = val;
40+ this.next = next;
41+ }
42+
43+ // ๋ฆฌ์คํธ ๋ง๋ค๊ธฐ
44+ const node3 = new ListNode(3); // ๋ง์ง๋ง ๋
ธ๋
45+ const node2 = new ListNode(2, node3); // node2 โ node3
46+ const head = new ListNode(1, node2); // head โ node2 โ node3
47+
48+ // ํ์ธ
49+ console.log(head.val); // 1
50+ console.log(head.next.val); // 2
51+ console.log(head.next.next.val); // 3
3752 */
You canโt perform that action at this time.
0 commit comments