Skip to content

[s0ooo0k] WEEK2 solutions #1767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 3, 2025
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 climbing-stairs/s0ooo0k.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
/*
* 시간복잡도 O(n)
* 공간복잡도 O(n)
*/
public int climbStairs(int n) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (n == 1) return 1;
if (n == 2) return 2;

예외는 이렇게 써주는 것도 명확해서 좋다고 생각합니다.

추가적으로 풀어보신다면 변수 2개만 쓰는 공간 최적화 O(1)으로도 풀 수 있습니다.

Copy link
Member Author

Choose a reason for hiding this comment

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

해당 방식으로 쓰는게 더 명확해보이네요 :) 조언 감사합니다!

int[] piv = new int[n+1];
piv[0]=1;
piv[1]=2;

for(int i=2; i<n; i++) {
piv[i]=piv[i-1]+piv[i-2];
}
return piv[n-1];
}
}

23 changes: 23 additions & 0 deletions valid-anagram/s0ooo0k.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
Copy link
Contributor

Choose a reason for hiding this comment

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

정렬 없이 카운팅 방식으로만 풀어보셔도 좋을 것 같아요.

/*
* 초반 풀이시 단순 s의 문자가 t에 포함하는지만 확인하여 제대로된 비교를 못함 (ex "sass" vs "saas")
* 따라서 정렬 후 비교하는 방식으로 전환
*
* 시간복잡도 O(n log n)
* 공간복잡도 O(n)
*/
public boolean isAnagram(String s, String t) {

if(s.length() != t.length())
return false;

char[] chr1 = s.toCharArray();
char[] chr2 = t.toCharArray();

Arrays.sort(chr1);
Arrays.sort(chr2);

return Arrays.equals(chr1, chr2);
}
}

15 changes: 15 additions & 0 deletions validate-binary-search-tree/s0ooo0k.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 시간복잡도 : O(n)
*/

class Solution {
public boolean isValidBST(TreeNode root) {
return valid(root, Long.MIN_VALUE, Long.MAX_VALUE);
}
private boolean valid(TreeNode node, long min, long max) {
if(node==null) return true;
if(node.val <= min || node.val >=max) return false;
return valid(node.left, min, node.val) && valid(node.right, node.val, max);
}
}