개발공부/LeetCode

    [JavaScript] 22. Generate Parentheses 풀이과정 쉬운 설명 - backtrack, recursion 활용

    [JavaScript] 22. Generate Parentheses 풀이과정 쉬운 설명 - backtrack, recursion 활용

    22. Generate Parentheses - Mideum Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2: Input: n = 1 Output: ["()"] 문제 설명 문제 해결 전략 1. 우선 n값이 3이면 "(" 개수와 ")"개수가 각각 3개씩 총 6개 이어야 합니다. 2. 하지만 갯수만 매치시켜서 찾을 경우 ")))(((" 이런 패턴에도 통과시키기 때문에, 이런 걸 걸러낼 필터가 필요합니다. 3. 그리고..

    [LeetCode] 190. Reverse Bits - JAVASCRIPT 풀이 과정 , 개념 설명 - 비트 연산자

    190 - Reverse bits 주어진 32비트 unsigned integer를 역순으로 만들어 리턴하는 문제입니다. 결과는 아래와 같습니다. 문제 풀이 전 이해해야 할 것 처음 이문제를 풀때 저는 n값이 이진법으로 이루어진 string이(ex) 010110101) 들어가는 줄 알았는데 콘솔로 확인해보니 정수가 들어가 있는걸 그때 알았습니다. 그러므로 우리는 32bit 정수상태인 파라미터를 이진 string으로 바꾼 후 그 이진 스트링의 거꾸로 된 값을 찾은 후 그걸 다시 32bit 정수 상태로 반환해야 하는 것입니다. 비트란 위에서 32bit와 이진수들이 나왔는데 두 개념을 이해하기위해 먼저 비트를 이해해야 합니다. 그렇다면 비트는 무엇일까요? 비트는 true(1)와 false(0)로 이루어진 이진법..

    [Kotlin] 선형리스트를 활용한 문제풀이 LeetCode: Delete Node in a Linked List

    [Kotlin] 선형리스트를 활용한 문제풀이 LeetCode: Delete Node in a Linked List

    문제 Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly. It is guaranteed that the node to be deleted is not a tail node in the list. linked list(선형리스트)에서 하나의 node를 지우는 함수를 만들어야합니다. linked list는 아래와 같습니다. 이 문제에선 linkedlist에서 가장 앞에있는 node를 접근할수없게됩니다. 그리고 마지막자리 node는 지워질수..

    [Kotlin] indexof 사용법 및 활용 LeetCode: Implement strStr() 쉬운풀이

    [Kotlin] indexof 사용법 및 활용 LeetCode: Implement strStr() 쉬운풀이

    문제 Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Clarification: What should we return when needle is an empty string? This is a great question to ask during an interview. For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf(). 일치하는게 없으면..