Algorithm/알고리즘 예제코드

    Knapsack(배낭알고리즘)

    let ting = [{ v:0, w:0, }]; for(let i=1; i

    투 포인터

    주어진 배열의 크기가 N이고, 찾고자 하는 구간합이 M 일떄. function sol() { let answer = 0; let start = 0; let end = 0; let sum = 0; while(start

    [JS]MaxHeap

    class maxHeap{ constructor(){ this.heap = [null]; } size() { return this.heap.length - 1; } swap(a,b) { [this.heap[a], this.heap[b]] = [this.heap[b], this.heap[a]]; } add(value) { this.heap.push(value); let cur = this.heap.length - 1; // 제일 나중 노드에 새로 들어온 원소를 추가한다. let parent = Math.floor(cur / 2); while(cur > 1 && this.heap[parent] < this.heap[cur]) { // 부모노드의 원소가 더 작으면 현재노드의 원소와 바꿔준다. this.swap..

    부분합

    for (int i = 0; i > A >> B >> K; arr[A] += K; arr[B + 1] -= K; } for (int i = 1; i

    DP(동전 교환, LCS)

    동전 교환 동전 교환 관련 문제 접근 :: 마이구미 이번 글은 "동전 교환" 에 관한 알고리즘을 다뤄볼 것이다. 백준 알고리즘 사이트에서 알고리즘 분류에서 "동전 교환"을 볼 수 있다. 2293번 동전 1, 2294번 동전 2, 11047번 동전 0 문제를 통해 다룬 mygumi.tistory.com n가지 종류의 동전을 갖고 가치의 합이 k원이 되는 경우의 수. dp[0] = 1; for (int i = 0; i < n; i++) { for (int j = coin[i]; j

    소수판별

    public class Main { public static boolean isPrime(int num){ for(int i=2; i*i

    Sort

    1. bubble sort function bubbleSort (input) { const len = input.length; let tmp = null; for (let i = 0; i input[j + 1]) { // Swap tmp = input[j]; input[j] = input[j + 1]; input[j + 1] = tmp; tmp = null; } } } return input; } 2. selection sort function selectionSort (input) { const len = input.length; let tmp = null; for (let i = 0; i < ..

    정규식

    모든 파일 검색 /[a-zA-Z]:\\.+\.(jpg|gif|png)/gi \.(txt|exe|png) 또는 .[^\.]*\.(txt|exe|png) == 수정중 ==