분류 전체보기 (140) 썸네일형 리스트형 [Stack] 과제는 끝나지 않아! - Baekjoon 17952번 Swift 문제 : https://www.acmicpc.net/problem/17952 17952번: 과제는 끝나지 않아! 성애는 이번 학기에 전공을 정말 많이 듣는다. 이로 인해 거의 매일을 과제를 하면서 보내고 있다. 그런데도 과제가 줄어들 기미가 보이지 않는데, 바로 분단위로 과제가 추가되고 있기 때문이 www.acmicpc.net 풀이방법 입력받은 것 첫번째가 1일 때만 stack(점수, 시간초)에 넣는다. stack의 마지막 원소를 1초마다 시간초를 -1 빼준다 시간초가 0이되면 result에 해당 점수를 더해준다. 이 문제에서 골치아팠던게 Int($0)으로만 하면 시간초과가 난다. subString을 String으로 바꿔줘야 통과가 된다. 코드 // // main.swift // Assignment //.. [투포인터] Minimize Maximum Pair Sum in Array - LeetCode Swift 문제 : https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/ Minimize Maximum Pair Sum in Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이방법 오름차순으로 정렬후 가운데 인덱스를 구해서 양쪽으로 더한것들 중 제일 큰것을 반환한다. 코드 class Solution { func minPairSum(_ nums: [Int]) -> Int { let SortedNu.. [Heap] 우선순위 큐 - LeetCode Swift 문제 : https://leetcode.com/problems/find-k-pairs-with-smallest-sums/ Find K Pairs with Smallest Sums - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 우선 이 문제는 우선순위큐를 먼저 이해하고 직접 코드로 구현할 수 있는가? 묻는 문제이다. 우선순위큐란 큐에 들어온 순서에 상관없이 우선순위가 높은 데이터가 먼저 나오는 것이다. 코드 // // main.swift // FindKPair.. [Stack] daily-temperatures - LeetCode Swift 문제 : https://leetcode.com/problems/daily-temperatures/ Daily Temperatures - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이방법 : monotonic stack 단조로운 스택이란 뜻으로 스택을 증가시키는 형태나 감소시키는 형태로 유지하는 것이 핵심이다. 단조로운 형태로 가다가 그 형태가 벗어나면 앞에 것을 하나씩 인덱스 차이를 구하며 제거한다. 우선 배열전체를 도는 반복문을 만든다. 스택에 한개씩 넣.. [DFS] keys and rooms - LeetCode Swift 문제 : https://leetcode.com/problems/keys-and-rooms/ Keys and Rooms - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이방법 큐에 0번째 룸의 열쇠들을 다 넣는다. 큐의 첫번째 열쇠로 열 수 있는 방을 딴다. 그 방을 방문했던 적이 있다면 통과 없다면 또 그방 안에 있는 모든 열쇠를 큐안에 집어 넣는다. 코드 import Foundation class Solution { func canVisitAllRooms(.. [정렬] 줄 세우기 - 백준 2252번 Swift 문제 : https://www.acmicpc.net/problem/2252 2252번: 줄 세우기 첫째 줄에 N(1 ≤ N ≤ 32,000), M(1 ≤ M ≤ 100,000)이 주어진다. M은 키를 비교한 회수이다. 다음 M개의 줄에는 키를 비교한 두 학생의 번호 A, B가 주어진다. 이는 학생 A가 학생 B의 앞에 서야 한다는 의 www.acmicpc.net 위상정렬 문제이다. 위상 정렬이란 어떤 일을 하는 순서를 찾는 알고리즘이다. 즉, 방향 그래프에 존재하는 각 정점들의 선행 순서를 위배하지 않으면서 모든 정점을 나열하는 것 개념 -> https://gmlwjd9405.github.io/2018/08/27/algorithm-topological-sort.html [알고리즘] 위상 정렬(Topolo.. Frame과 Bounds의 차이 frame The frame rectangle, which describes the view’s location and size in its superview’s coordinate system. superView의 좌표 시스템에서의 뷰의 좌표와 크기를 알려준다. (이때 SuperView는 한 단계 상위 View) bounds The bounds rectangle, which describes the view’s location and size in its own coordinate system. 자신의 좌표 시스템에서 뷰의 좌표와 크기를 알려준다. Frame과 Bounds는 UIView의 instance property입니다. 근데 위에 보니까 타입이 CGRect?? 그럼 CGRect의 프로퍼티인 or.. [Queue] 배열 구간 최솟값/최댓값 구하기 문제 : https://leetcode.com/problems/sliding-window-maximum/ Sliding Window Maximum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 : https://www.acmicpc.net/problem/11003 11003번: 최솟값 찾기 N개의 수 A1, A2, ..., AN과 L이 주어진다. Di = Ai-L+1 ~ Ai 중의 최솟값이라고 할 때, D에 저장된 수를 출력하는 프로그램을 작성하시오. .. 이전 1 ··· 11 12 13 14 15 16 17 18 다음