22. Generate Parentheses
if the parenthesis is correct, each parenthesis must be closed. which means, each closed parenthesis can be replaced with '()', that must be also complete. and
Problem solutions — approach, intuition, and complexity.
if the parenthesis is correct, each parenthesis must be closed. which means, each closed parenthesis can be replaced with '()', that must be also complete. and
the approach was simple. I wanted to make it time complexity so I tried to check possible pelindrome that has center on i-th element. as it written on the hint,
i focused on the step of the process. in the problem, there are two big steps. which are drink and exchange.the order of those steps doen't really matter so I p
I just followed the steps i mentioned before.
the apprach was correct. you must divide the big problem into sub problems, and solve them. so if you choose one triangle from a polygon, the rest part will be
i used recursion, if the array length is 1, it returns the number. and if else, we do the calculation and reduce the size of array by one.
first, I extract its negative sign, and make a reversing function. and then, it manage the errors that can occur becuase of overflow.
I followed the instruction from the question. it removes the leading spaces, and find the sign symbol. then, read the number one by one. if wrong letter appears
it focus on the possibility of growing. I dont' know how to show mathematically, but it works like this. there are two pointers from left and right ends. you ca
first i found out the max length of it is 15 so i prepared for a string memory of 16 chars. 1 is for char. then, I build up the roman number one by one. you
I apprached this question by thinking i'm actually writing the string with zigzag patterns. so I made a list for each rows, and add one charanter one by one on
easy approach. just add correct string to the list and return it. to get the correct, string use conditional statements.
I used the easier way to solve this. it uses two while loops to findout it has pair or not. so for each index, it goes trough whole string and find its pair. if
we know using xor operator, this problem can be solved super easily. mathematically, there are three properties of xor operator that can show this code is the s
on the question, it explains the subsequence is just same list with some deleted characters. so I go through the string and comparing them while ignoring delete
as I said management should be done on the grandpa level node. lets don't think this now and build a base cases for recursion. 1. if root is null -> return 0 2.
binary search algorithm works for this problem. guess the middle value and depends on the answer, you update the possible range of the picked number. if there a
i still don't know what are ransomNote and magazines are but I thought they are like ingredients and the food. so to make a food of 'aab', you need two 'a' and
the approach is simple, if the number is power of four, only 1 will left if you devide the number by 4 repeatedly. and i used bit manipulation to measure it's m
i could just switch first and last character, and second and second last character, and so on. you don't need to consider whether it has even or odd length, bec
to solve this problem, i used two pointer approach. there are two pointers on the string, one starts from the front and the other starts from the back. they bot
python has wonderful datatype 'set' that supports all the mathematical functions of set. it uses some hash map method, and it's pretty hard to build it my own o
just compare the num with all the perfect squares from 1 to max.
you can definitely win if your friends has only 4 stones left. because if he takes 1, you can take all 3 and win. if he takes 2, you can take all 2 and win. if
I took the easiest apprach. the array is just an array, and the sum finds the sum using for loop.
compare the number with all the possible power of threes.
0 --> 0 (0) 1 --> 1 (1) 2 --> 10 (1) 3 --> 11 (2) 4 --> 100 (1) 5 --> 101 (2) 6 --> 110 (2) 7 --> 111 (3) 8 --> 1000 (1) 9 --> 1001 (2) 10--> 1010 (2) 11--> 101
as i mentioned, the binary search algorithm works well. determine the middle value is bad or good, and reduce the size of set more and more. I struggled a bit o
there is a fast pointer and slow pointer. they both start from 0 and fast pointer just rush to the end and just read the values. at the same time, slow pointer
the first part shows the string has unique pair to pattern and second part shows the pattern has uniqe pair to the string. it works well.
As i mentioned, I used recursion. case 1 when its empty tree, it returns empty array. case 2 when it is a leaf node, [val] is the output. case 3 else, its addit
if it is single digit, return it. or, do the same process.
if n = 1, return true if n is multiple of 2, run the same function on n/2 if n is multiple of 3, run the same function on n/3 if n is multiple of 5, run the sam
if the array contains 0 to n with one missing number k, the sum of the array will be by the Gauss's method. so I calculated k by reverse.
if n is power of 2, in binary it will look like 0001000...0 then, if you do n-1, it will look like 00001111...1 then, if you take & operator to them, it will al
my apprach was like this. if we can find the midpoint of the linked list, we only need to reverse the first half and then compare it. it was a bit challenging t
the apprach is simple. it is just like counting algorithm for any tree, but it has some additional feature that returns if the tree is fully filled.
just created a node struct and made a stack. there's nothing to talk about this. this is so classic.
using recursion to solve this. flip the left and flip the right and switch left and right. that's all.
let's say the array is an array of balls that has numbers on them. and trying to find two balls that are close and has the same number. what I can do is take a
first, we convert both strings into the list of integers. the same letter will be replaced to the same number. for example, 'FOO' will be '011', and 'BAR' will
just travel trough linked list and change the next value as you move one.
according to the wikipedia, only one and seven are happy number. And I don't know how but, every cycle will contain at least one single digit number. so I loope
it removes the target value nodes.
there is nothing to say about the apprach. just read this wikipedia page. https://en.wikipedia.org/wiki/Boyer%E2%80%93Mooremajorityvotealgorithm
it calls the help function. I created the help function to send the length of string as an argument of function. Otherwise, it would increase the complexity by
save each digits in hash, and re-build it.
from moving on each bits, count the number of ones.
this question sucks. it's not even converting base question. and it is so stupid to solve this with C
The approach to this problem is very intuitive. firstly, the string might contain unnecessary letters such as spaces, quotemark, or colon or something. therefor
The approach to this problem is more Mathematical. There are four key property of XOR operator to solve this problem. 1. identity of XOR is 0 : 2. XOR is Commut
so, firstly I need to prepare for the memory, so I made a function that counts the of nodes of the tree. than malloc an array that can carry that amount of inte
this is the same question with previous one so I just copy and pasted it. There will be nothing to say about this. if you want more info about this, goto 026.pr
https://velog.io/@jw9603/LeetCode-160.-Intersection-of-Two-Linked-Lists
the approach is pretty complex, but here me out. from scanning the prices from the beginning, it find the starting point. if you find the smaller starting point
Firstly, I focused more on creating the memory thing, using malloc, and then started to put numbers in that. It was building the triangle from the top, so I cou
I made two array that does exactly same thing with previous question.
the apprach is very stupid, but works. it itterate from 1 to the number itself, until the number is greater than target num devided by the number. it works!
I could find out two apprachs. one is using recursion, the other is using loop. I thought second one looks more efficient, so I did with that. it's like fibonac
from the beginning, It look at the next node, and it have the same value with current one, it removes the second one. that's all.
Therefore, I decided to build the merged array from the behind. the answer will be build from the biggest number with non-increasing order. this worked well. th
first, I have to find out how long will the answer be, which is number of nodes, so I made count tree function. Then, I tried to make reculsive function, but pu
two trees are identical when their values and two childs are identical. we can use reculsion for that easily.
The second apprach is reversing the binary string. by reversing them, the problem occured from approach 1 is almost solved. because after the reversion, head of
The problem was that if you pass the starting point of needle by comparing it with it's tails, the program will never find the needle. therefore, there should b
The approach to this question is binary search for sorted array. so I used idea of sub-array and offset of that array relative to the original one. and that wor
As I described on the intuition part, i made a variable called 'prev', which stores previous character. the initial value of it should be a space, so that s sta
Firstly, it was necessary to find out how much memory the answer will take. if the number is with tons of 9s, it will need new digit. Therefore, I made a functi
the apprach to this problem was I wanted to use a for loop. because the job is pretty simple, so I could done it by reading through the list one by one. and it
same with 008 question but compare the value with val. not prev.
I also used reculsive algorithm to this problem, just like others. I love reculsive functions. in this case, the function should return 1 when the tree is the l
first, it returns false if the tree is empty. no tree means no path. and if it is leaf and target is the value, it returns true. or, it calls their child for th
for every node on the linked list, it loop through the whole linked list and comparing with the next node of the node I'm looking at.which has horrible time com
As I mentioned above, the definition of balanced tree contains the concept of height of a tree inside. therefore, I thought the calculating height was essential
As i mentioned from the intuition part, the apprach was pretty simple. I first found out I need to deal with the middle value of the sorted array since It shoul
As I said, I decided to break down the prooblem into two different parts. First was fliping one side of the tree, and another part is comparing two trees. if a
I used the reculsive method to solve the problem. Firstly, I found the base case, where the the null tree has zero depth, and the depth of a tree is its deepest