문제: 위 코드로 채점을 하면 정확성 테스트 케이스 2번째에서 계속 실패 테스트 2 〉 실패 (4.39ms, 37.7MB) 원인 배열의 sort 메소드를 그대로 사용하면 문자로 인식하고 정렬해서 해결 배열의 원소들이 숫자로 인식되어 정렬되도록 하자
source: 104. Maximum Depth of Binary Tree
i + ""을 사용하지 말고 Integer.toString()을 사용하자
Write a function that reverses a string. The input string is given as an array of characters char\[].Do not allocate extra space for another array, yo
Runtime: 56 ms, faster than 82.45% of JavaScript online submissions for Binary Tree Level Order Traversal II.Memory Usage: 34.7 MB, less than 100.00%
WeightedQuickUnionUFWithPathCompression
(... 작성 중)O(n^2)은 연산이 증가할 수록 성능이 나빠진다 => O(n^2) 이하인 알고리즘을 선택해야 한다.
Given a string s, return the longest palindromic substring in s.Input: s = "babad"Output: "bab"Note: "aba" is also a valid answer.Input: s = "cbbd"Out
const log = console.log;function solution(jobs) { // 작업 갯수 const jobsLen = jobs.length;}
Given a string s containing just the characters '(', ')', '{', '}', '' and '', determine if the input string is valid.An input string is valid if:Open
This is another way to solve this problem. It is a good example of using bitwise operation
time complexity => best: nlognspace complexity => best:
ComplexityTime: O(N)Space: O(1)
Good morning! Here's your coding interview problem for today.This problem was asked by Airbnb.Given a list of integers, write a function that returns
Is it a node?Is it a array?what is pos? Is it a index where Node start repeating?Extreme case? head = null?constraints?where does this come from?using
Time: O(N)Space: O(1), constant
Time: O(nlogn) => sorting nlogn, comparing n: nlognSpace: O(n) or O(1) => some languages, a string is an char array
Time: O(N), ex) 2 => need 2 stepsSpace: O(1), just need count
Time: O(n^2), cuz every time check if root is a unival tree, need to evalueate subtreesSpace: O(1)Better solutionwhat if count unival tree from each l
Time: O()Space:O(n)
node color == adjacent node color must be false for a graph to be a bipartiteTime: O(N), iter every node in the graph once and iter its child onceSpac
iter a list only once
Constance space means no matter how n increases the space ur code using stays equal.
Time: O(mn + nlogn)Space: O(m + k)
Time: O(N)Space: O(1)
Time: O(N)Space: O(N), how to make this to O(1)?O(1) space
Time: O(N),Space: O(1), some language String is a char\[]
with whilewith recursionTime: O(logY)Space: O(1), only cnt;
problem code
problem coding
problem c
Time: O(N)Space: O(N)from leetcode "SlovakUnion"The idea is a(x + y) <=> ax + ayTIME: O(N)Space: O(1)
Time: O(N)Space: O(1)but code is too longTime: O(nlogn), 100 times slower than 1st try
push -> peek: check if pop element is equal if yes -> pop, continueif no -> pushbreak ifpop index is equal to length of pushed aray andstack is not em
problem code
I don't need to track the sequence of numbers....just need to track max frequency and frequency of each numbervar FreqStack = function() { this.top
problem code 1st try
Time: O(N); two for loop iterating NSpace: O(N); HashMap contains N elements at mostTime: O(nlogn); sortingSpace: O(1)
Time: O(NlogN)Space: O(1)
if there is a ListNode that both A and B have, the reference address of the ListNode is equalTime: O(N)Space: O(N)
Time: O(N)Space: O(level of Tree)
abba => bb is palindromic. for (x)bb(y), x == y then, it is palindromic
problem code 1st try: simple
need to understand difference between substrings and subsequencesabbab => subsequences = aa, bbb, abba, abbab, ... is palindromic subsequenceswe can r
problem code 1st try: Brute force Time: O(N^3) Space: O(1) 2nd try: sliding door
problem c
add 4xx 9xx where x is 0 or '', this problem becomes a lot easier.Time: O(1)Space: O(1)
problem co
2nd try:
problem code
Time: O(log^2N), count(1 << i) logN, equals LogNSpace: O(Log^N), why? there are 30 arrays for power of 2s < 10000000000
Time: O(N), deleteSpace: O(N)
problem code 1st try: check A[i] > A[i +2], if yes, return false
Time: O(1)Space: O(1)
Time: O(4^4)space: O(4^4)
problem