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
18 changes: 18 additions & 0 deletions climbing-stairs/hjeomdev.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
List<Integer> list = new ArrayList<>();
public int climbStairs(int n) {
list.add(0);
list.add(1);
list.add(2);
return step(n);
}

public int step(int n) {
if (list.size() > n && list.get(n) != null) {
return list.get(n);
}
int result = step(n - 1) + step(n - 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

이렇게 DP 테이블의 가장 최근 n개의 원소만 사용하는 경우에는 O(n) space의 DP 테이블 대신 O(1)space의 변수를 사용해서 공간 복잡도를 한 단계 최적화 할 수 있을 것 같습니다!

list.add(result);
return result;
}
}
21 changes: 21 additions & 0 deletions valid-anagram/hjeomdev.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) {
return false;
}

String[] sList = s.split("");
Arrays.sort(sList);
String[] tList = t.split("");
Arrays.sort(tList);
Copy link
Contributor

Choose a reason for hiding this comment

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

정렬을 이용해서 풀이하셨네요! 정렬을 하게 되면 시간 복잡도가 O(nlogn)이 되는데요, 카운팅을 이용하면 시간 복잡도를 약간 더 최적화 할 수 있어서 이렇게도 한 번 풀어보시는 걸 추천드려요~!


for (int i = 0; i < s.length(); i++) {
// System.out.println(sList[i] + " " + tList[i]);
if (!sList[i].equals(tList[i])) {
return false;
}
}

return true;
}
}