File tree Expand file tree Collapse file tree 5 files changed +135
-0
lines changed Expand file tree Collapse file tree 5 files changed +135
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ // tag renovizee 3week
4
+ // https://github.com/DaleStudy/leetcode-study/issues/254
5
+ // https://leetcode.com/problems/valid-palindrome/ #39 #Medium
6
+ class Solution {
7
+ // Solv1 :
8
+ // ์๊ฐ๋ณต์ก๋ : O(n)
9
+ // ๊ณต๊ฐ๋ณต์ก๋ : O(n)
10
+ public List <List <Integer >> combinationSum (int [] candidates , int target ) {
11
+
12
+ }
13
+ }
14
+
15
+ //-------------------------------------------------------------------------------------------------------------
16
+ // Java ๋ฌธ๋ฒ ํผ๋๋ฐฑ
17
+ //
18
+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
1
+
2
+
3
+ // tag renovizee 3week
4
+ // https://github.com/DaleStudy/leetcode-study/issues/268
5
+ // https://leetcode.com/problems/valid-palindrome/ #91 #Medium
6
+ class Solution {
7
+ // Solv1 :
8
+ // ์๊ฐ๋ณต์ก๋ : O(n)
9
+ // ๊ณต๊ฐ๋ณต์ก๋ : O(n)
10
+ public int numDecodings (String s ) {
11
+
12
+ }
13
+ }
14
+
15
+ //-------------------------------------------------------------------------------------------------------------
16
+ // Java ๋ฌธ๋ฒ ํผ๋๋ฐฑ
17
+ //
18
+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
1
+
2
+
3
+ // tag renovizee 3week
4
+ // https://github.com/DaleStudy/leetcode-study/issues/275
5
+ // https://leetcode.com/problems/valid-palindrome/ #53 #Medium
6
+ class Solution {
7
+ // Solv1 :
8
+ // ์๊ฐ๋ณต์ก๋ : O(n)
9
+ // ๊ณต๊ฐ๋ณต์ก๋ : O(n)
10
+ public int maxSubArray (int [] nums ) {
11
+
12
+ }
13
+ }
14
+
15
+ //-------------------------------------------------------------------------------------------------------------
16
+ // Java ๋ฌธ๋ฒ ํผ๋๋ฐฑ
17
+ //
18
+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
1
+
2
+
3
+ // tag renovizee 3week
4
+ // https://github.com/DaleStudy/leetcode-study/issues/232
5
+ // https://leetcode.com/problems/number-of-1-bits #191 #Easy
6
+ class Solution {
7
+ // Solv2 :
8
+ // ์๊ฐ๋ณต์ก๋ : O(1)
9
+ // ๊ณต๊ฐ๋ณต์ก๋ : O(1)
10
+ public int hammingWeight (int n ) {
11
+ int result = 0 ;
12
+ for (int i = 0 ; i < 32 ; i ++) {
13
+ if (((n >> i ) & 1 ) == 1 ) {
14
+ result ++;
15
+ }
16
+ }
17
+ return result ;
18
+
19
+ }
20
+ // // Solv1 :
21
+ // // ์๊ฐ๋ณต์ก๋ : O(log n)
22
+ // // ๊ณต๊ฐ๋ณต์ก๋ : O(1)
23
+ // public int hammingWeight(int n) {
24
+ // int result = 0;
25
+ // int current = n;
26
+ // while (current >= 2) {
27
+ // if ((current % 2) == 1) {
28
+ // result++;
29
+ // }
30
+ // current = current / 2;
31
+ // }
32
+ // if (current == 1) {
33
+ // result++;
34
+ // }
35
+ // return result;
36
+ //
37
+ // }
38
+ }
39
+
40
+ //-------------------------------------------------------------------------------------------------------------
41
+ // Java ๋ฌธ๋ฒ ํผ๋๋ฐฑ
42
+ // 1) String s=Integer.toBinaryString(n); ์ซ์๋ฅผ ์ด์ง์ string์ผ๋ก ๋ณํํ๋ ๋ฐฉ๋ฒ
43
+ // 2) ์ซ์๋ฅผ ๋นํธ ์ฐ์ฐํ๋ ๋ฐฉ๋ฒ n >> i ๋ ์ ์ n์ i ๋งํผ ์ค๋ฅธ์ชฝ์ผ๋ก shift ํจ, ex) 1011 -> 0101
44
+ // 3) & ์ ๋นํธ์์ and ์ฐ์ฐ์ด๊ณ & 1์ ๋ง์ง๋ง ๋นํธ ๊ฒ์ฌ๋ก ํน์ํ๊ฒ ์ฌ์ฉ๋จ, ๋๋ค 1์ธ ๊ฒฝ์ฐ๋ง 1
45
+ //-------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
1
+
2
+
3
+ // tag renovizee 3week
4
+ // https://github.com/DaleStudy/leetcode-study/issues/220
5
+ // https://leetcode.com/problems/valid-palindrome/ #125 #Easy
6
+ class Solution {
7
+ // Solv1 :
8
+ // ์๊ฐ๋ณต์ก๋ : O(n)
9
+ // ๊ณต๊ฐ๋ณต์ก๋ : O(n)
10
+ public boolean isPalindrome (String s ) {
11
+ // replaceAll(...): ๋ฌธ์์ด ์ ์ฒด๋ฅผ ํ ๋ฒ ์ํ โ O(n)
12
+ // trim(): ๊ณต๋ฐฑ์ ์์ชฝ ๋์์๋ง ํ์ โ O(n) ์ด๋ผ๊ณ ๋ณด์ง๋ง ๋ณดํต ๋ฌด์ ๊ฐ๋ฅํ ์์ค
13
+ // toLowerCase(): ๋ชจ๋ ๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ฐ๊ฟ โ O(n)
14
+ String cleanString = s .replaceAll ("[^a-zA-Z0-9]" , "" ).trim ().toLowerCase ();
15
+
16
+ int left = 0 ;
17
+ int right = cleanString .length () - 1 ;
18
+
19
+ //O(n)
20
+ while (left < right ) {
21
+ if (cleanString .charAt (left ) != cleanString .charAt (right )) {
22
+ return false ;
23
+ }
24
+ left ++;
25
+ right --;
26
+ }
27
+ return true ;
28
+
29
+ }
30
+ }
31
+
32
+ //-------------------------------------------------------------------------------------------------------------
33
+ // Java ๋ฌธ๋ฒ ํผ๋๋ฐฑ
34
+ // 1) char[] ๋๋ฌธ์ Char ๊ฐ ์๋๊ณ ์์คใด์
35
+ // 2) ~.equals๋ char์์ ์ ๊ณต๋์ง ์์
36
+ //-------------------------------------------------------------------------------------------------------------
You canโt perform that action at this time.
0 commit comments