Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions best-time-to-buy-and-sell-stock/essaysir.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Two Pointers
  • 설명: 로직이 한 번의 순회로 최적의 차이를 구하는 Greedy 패턴이며, 최소의 가격 인덱스(앞부분 포인터)와 현재 가격과의 차이를 비교하는 Two Pointers 흐름이 같이 적용됩니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 한 번의 순회로 최적의 매도 시점을 찾기 위해 최솟값 인덱스를 추적합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public int maxProfit(int[] prices) {
int result = 0;
// prices = [7,1,5,3,6,4]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최소값 대신 최소 인덱스를 들고 가는 접근도 깔끔하네요.
인덱스로 잡으면 나중에 '며칠에 샀는지'까지 확장할 때 바로 쓸 수 있는 여지가 있어 좋네요!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견들 너무 감사합니다! 앞으로, 코딩 테스트 하면서 적용해볼 수 있도록 노력하도록 하겠습니다.

int lt = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lt는 무슨 약어일까요? 추측하기 어려운 약어로 보여서 의미를 담는 변수명을 사용하시면 좋을 거 같아요.

for ( int i = 1 ; i < prices.length; i ++){
if ( prices[i] < prices[lt] ){
lt = i;
}
else{
result = Math.max(result, prices[i] - prices[lt]);
}
}

return result;
Comment on lines +11 to +15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최대 이익을 나타내는 값이어서 그 의미를 나타내는 변수명을 쓰는건 어떨까요?

}
}
38 changes: 38 additions & 0 deletions encode-and-decode-strings/essaysir.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy, Divide and Conquer, Dynamic Programming, Two Pointers, Sliding Window, Fast & Slow Pointers, BFS, DFS, Backtracking, Union Find, Trie, Bit Manipulation, Monotonic Stack, Heap / Priority Queue, Binary Search
  • 설명: 문자열 인코딩 길이(prefix length)와 구분자('#')를 이용해 문자열을 순차적으로 파싱하는 방식으로, 문자열의 구성 요소를 순회하며 구분을 이용해 부분 문자열을 분리한다. 특정 데이터 단위를 분리하고 재구성하는 패턴에 해당한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(sum of lengths)
Space O(sum of lengths)

피드백: 정확히 각 문자열의 길이를 먼저 기록하고 문자열 자체를 이어붙이는 방식으로 인코딩합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public class Solution {
/*
* @param strs: a list of strings
* @return: encodes a list of strings to a single string.
*/
public String encode(List<String> strs) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'#'이 encode/decode 양쪽에 매직 리터럴로 중복되기 때문에, private static final char DELIMITER = '#';로 추출해서 두 메서드의 인코딩 계약이 한 곳에서 관리되면 나중에 구분자 바꿀 때 한쪽만 수정하는 실수를 예방할 수 있을 것 같아요!

StringBuilder sb = new StringBuilder();
for (String s : strs) {
sb.append(s.length());
sb.append('#');
sb.append(s);
}
return sb.toString();
}
Comment on lines +7 to +14

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구분자 없이도 가능한데 풀어보셔도 좋을 거 같습니다.


/*
* @param str: A string
* @return: decodes a single string to a list of strings
*/
public List<String> decode(String str) {
List<String> res = new ArrayList<>();
int i = 0;
while (i < str.length()) {
// '#' 앞의 숫자를 길이로 파싱
int len = 0;
while (str.charAt(i) != '#') {
len = len * 10 + (str.charAt(i) - '0');
i++;
}
i++; // '#' 건너뛰기

// 정확히 len 글자만 잘라내기
res.add(str.substring(i, i + len));
i += len;
}
return res;
}
}
23 changes: 23 additions & 0 deletions group-anagrams/essaysir.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Divide and Conquer
  • 설명: 문자 문자열을 정렬한 키로 그룹화하여 같은 아나그램들을 묶는 방식으로 해시맵에 분류하는 패턴. 각 키로 그룹을 구성하고 최종 결과를 모으는 흐름이 특징이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n * k log k)
Space O(n * k)

피드백: 각 문자열 길이에 따라 정렬 비용이 지배적이며, 그룹화에 해시맵을 사용합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public List<List<String>> groupAnagrams(String[] strs) {
// 아나그램을 그룹별로 만들어라
// 아나그램 -> 각 string 을 배치해서 만들 수 있는 가 ?
// 각 알파벳이 몇개가 있는 가 ?
List<List<String>> answer = new ArrayList<>();
Map<String, List<String>> map = new HashMap<>();

for ( int i = 0; i < strs.length; i ++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

루프 안에서 i 자체를 쓰지 않고 strs[i]로 값만 참조할 때 가독성을 향상시키기 위해서 enhanced for-loop을 써보는 것도 좋을 것 같습니다!

char[] chars = strs[i].toCharArray();
Arrays.sort(chars);

String s = new String(chars);
map.computeIfAbsent(s, k -> new ArrayList<>()).add(strs[i]);
}

for (List<String> group : map.values()) {
answer.add(group);
}

return answer;
}
}
Loading