개발공부

    [JavaScript] 21. Merge Two Sorted Lists - 쉬운설명

    [JavaScript] 21. Merge Two Sorted Lists - 쉬운설명

    21. Merge Two Sorted Lists You are given the heads of two sorted linked lists list1 and list2. Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list. Example 1: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: list1 = [], list2 = [] Output: [] Example 3: Inp..

    [JavaScript] 206. Reverse Linked List - 쉬운설명, 인터뷰 필수 문제

    [JavaScript] 206. Reverse Linked List - 쉬운설명, 인터뷰 필수 문제

    206. Reverse Linked List - Easy Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] 해설 문제 해결 전략 릿코드 디스커션에서 가져온 이미지입니다. 이미지를 설명하자면, 3개의 포인터 current next prev를 사용하여 LinkedList를 reverse 해주는 것을 확인할수있습니다. 구현 전략 prev, current,..

    [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. 그리고..

    [Kotlin] Activity, fragment 사이 데이터 결과 전달 2가지 방법 Fragment Result Api, ViewModel - Under Tech Blog

    [Kotlin] Activity, fragment 사이 데이터 결과 전달 2가지 방법 Fragment Result Api, ViewModel - Under Tech Blog

    Fragment Result Api - 프래그먼트 간 결과전달 지금까지는 위와 같이 선택창을 띄운후, 프래그먼트의 결과 값을 전달할때, intent로 결과 값을 전달 하였습니다. 하지만 이때 위 방법을 사용했을때 문제는, 코드가 길어지고 코드 재사용 효율성이 떨어지게 됩니다. 이문제를 해결하기위해 1. ViewModel을 이용하여 Fragment -> Activity로 전달 2. Fragment result API를 통한 Fragment A -> Fragment B 로 전달하는 두가지 방법을 알아보도록하겠습니다. ViewModel을 이용하여 Fragment-> Activity로 전달 ViewModel을 이용한 데이터 전달 방법은 아래와 같습니다. 1. ViewModel을 생성해줍니다. class Sub..