Skip to content

Commit 4143862

Browse files
authored
Merge pull request #1778 from renovizee/main
[renovziee] WEEK 03 Solutions
2 parents 2ae8301 + 3e1b001 commit 4143862

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed

โ€Žcombination-sum/renovizee.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
//-------------------------------------------------------------------------------------------------------------

โ€Ždecode-ways/renovizee.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
//-------------------------------------------------------------------------------------------------------------

โ€Žmaximum-subarray/renovizee.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
//-------------------------------------------------------------------------------------------------------------

โ€Žnumber-of-1-bits/renovizee.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
//-------------------------------------------------------------------------------------------------------------

โ€Žvalid-palindrome/renovizee.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
//-------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
ย (0)