본문 바로가기

분류 전체보기351

[백준 13335] 트럭 www.acmicpc.net/problem/13335 13335번: 트럭 입력 데이터는 표준입력을 사용한다. 입력은 두 줄로 이루어진다. 입력의 첫 번째 줄에는 세 개의 정수 n (1 ≤ n ≤ 1,000) , w (1 ≤ w ≤ 100) and L (10 ≤ L ≤ 1,000)이 주어지는데, n은 다리를 건너는 트 www.acmicpc.net 구현 심각하다..공부하자 자료형은 큐를 사용한다. 트럭의 수만큼 큐에 push해주는데 q.size와 무게를 고려해야 한다. q의 사이즈가 w과 같다면 팝한다. q의 무게가 초과한다면 0을 푸쉬한다. 마지막에 time에 다리 길이만큼 더해주는게 포인트다. 왜냐면 맨 마지막 트럭이 길을 건너는데는 다리 길이만큼의 시간이 걸리기 때문이다. #include #includ.. 2020. 11. 4.
[leetcode 208] Implement Trie (Prefix Tree) Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie(); trie.insert("apple"); trie.search("apple"); // returns true trie.search("app"); // returns false trie.startsWith("app"); // returns true trie.insert("app"); trie.search("app"); // returns true Note: You may assume that all inputs are consist of lowercase letters a-z. All inputs are guaranteed to be non.. 2020. 11. 4.
[leetcode 206] Reverse Linked List Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? 문제풀이: - iterate써서 뒤집기 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * Lis.. 2020. 11. 4.
[leetcode 215] Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4] and k = 2 Output: 5 Example 2: Input: [3,2,3,1,2,4,5,5,6] and k = 4 Output: 4 Note: You may assume k is always valid, 1 ≤ k ≤ array's length. 문제풀이: - k번째 큰 수를 찾는다. 중복된 수도 존재! - 소팅한 후에 뒤에서 부터 숫자를 찾는다. class Solution { public:.. 2020. 11. 4.