전체 글

전체 글

    [JavaScript]34. Find First and Last Position of Element in Sorted Array - 쉬운설명

    34. Find First and Last Position of Element in Sorted Array Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7..

    [JavaScript] 946. Validate Stack Sequences 쉬운설명

    946. Validate Stack Sequences Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise. Example 1: Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1] Output: true Explanation: We might do the following sequence: push(1), push(2), push(3), push(4), po..

    [JavaScript] 138. Copy List with Random Pointer, 해시맵 사용, 쉬운설명

    [JavaScript] 138. Copy List with Random Pointer, 해시맵 사용, 쉬운설명

    138. Copy List with Random Pointer A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. n의 길이를 하고있는, 링크리스트가있고, 각 노드는 노말 포인터와, 랜덤 포인터를 가지고있고 이 랜덤 포인터는 리스트에 포함된 아무 노드나 null값을 가르킵니다. Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its val..

    [JavaScript] 61. Rotate List Medium  - 연결리스트 노드 옮기기, 쉬운설명, 반복문 사용

    [JavaScript] 61. Rotate List Medium - 연결리스트 노드 옮기기, 쉬운설명, 반복문 사용

    61. Rotate List Given the head of a linked list, rotate the list to the right by k places. Example 1: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Example 2: Input: head = [0,1,2], k = 4 Output: [2,0,1] 계획 문제 해결 전략 주어진 k만큼 반복하게 됩니다. 하지만 k가 linkedlist의 길이보다 클경우, example 2와 같이 k를 linkedlist length로 나눈 나머지값 만큼만 반복하면되기때문에 반복문에서 k% linkedlistLength의 값만큼 반복하게 합니다. linkedList 특성상 index로 요구하는 위치..

    [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..

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

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