본문 바로가기
반응형

Algorithm12

[프로그래머스 - 탐욕법] 체육복 카테고리 (Category) 작성 날짜 (Write Date) 최근 수정 날자 (Recent Write Date) 작성자 (Writer) Algorithm 2020.04.03. 19:55:27 2020.04.03. 19:55:27 Dev.Yang 점심시간에 도둑이 들어, 일부 학생이 체육복을 도난당했습니다. 다행히 여벌 체육복이 있는 학생이 이들에게 체육복을 빌려주려 합니다. 학생들의 번호는 체격 순으로 매겨져 있어, 바로 앞번호의 학생이나 바로 뒷번호의 학생에게만 체육복을 빌려줄 수 있습니다. 예를 들어, 4번 학생은 3번 학생이나 5번 학생에게만 체육복을 빌려줄 수 있습니다. 체육복이 없으면 수업을 들을 수 없기 때문에 체육복을 적절히 빌려 최대한 많은 학생이 체육수업을 들어야 합니다. 전체 학생의 .. 2021. 4. 3.
[LeetCode] 3Sum Closest 📄 [LeetCode] 3Sum Closest Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution. class Solution { func threeSumClosest(_ nums: [Int], _ target: Int) -> Int { var result: (Int, Int) = (Int.max, Int.zero) let sortedNums: Array =.. 2021. 3. 23.
[LeetCode] 3Sum 📄 [LeetCode] 3Sum Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Notice that the solution set must not contain duplicate triplets. func threeSum(_ nums: [Int]) -> [[Int]] { let testcase = nums.sorted() var result: [Int: Array] = [:] // Notice that the solution set must not contain d.. 2021. 3. 23.
[Algorithm - Concept] AVL Tree (named after inventors Adelson-Velsky and Landis) [Algorithm - Concept] AVL Tree (named after inventors Adelson-Velsky and Landis) AVL 트리(AVL tree)는 가장 초기에 나온 균형 잡힌(balanced) 이진 탐색 트리이다. 1962년 G.M. Adelson-Velskii와 E.M. Landis 가 그들의 논문 "An algorithm for the organization of information" 을 통해 발표했고 그들의 이름을 따서 지어졌다. AVL 트리는 각각의 노드(node, 분기점)마다 왼쪽과 오른쪽 부분 트리(sub-tree)의 높이 차이에 대한 정보를 가지며 부분 트리의 높이 차이가 1보다 크지 않은 성질을 가진다. 균형 잡힌 AVL 트리는 n개의 원소가 있을 때 O(l.. 2019. 9. 4.
반응형