본문 바로가기

분류 전체보기351

[백준 15779] Zigzag www.acmicpc.net/problem/15779 15779번: Zigzag 어떤 수열에서, 연속된 3개의 수를 보았을 때, 그 수가 단조증가 수열이거나, 단조감소 수열인 경우가 없으면 이 수열을 "지그재그 수열" 이라고 말한다. 좀 더 정확하게는, 길이 N의 수열 A가 모 www.acmicpc.net n이 5000까지이므로 브루트 포스 수열 안에 모든 숫자를 3개씩 확인해본다. 만약 지그재그 수열에 해당한다면 1씩 길이를 늘려주고 max값을 업데이트해준다. 지그재그 수열이 깨지면 다시 최소 지그재그 수열길이인 2부터 시작한다. #include #include using namespace std; int arr[5000]; int main(void) { int n; scanf("%d", &n); fo.. 2020. 11. 23.
[leetcode 172] Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. Follow up: Could you write a solution that works in logarithmic time complexity? Example 1: Input: n = 3 Output: 0 Explanation: 3! = 6, no trailing zero. Example 2: Input: n = 5 Output: 1 Explanation: 5! = 120, one trailing zero. Example 3: Input: n = 0 Output: 0 Constraints: 1 1개 = 총 6개 이다. 따라서 n>0일때까지 n /= 5; result += n; 을 해준다. c.. 2020. 11. 22.
[leetcode 171] Excel Sheet Column Number Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ... Example 1: Input: "A" Output: 1 Example 2: Input: "AB" Output: 28 Example 3: Input: "ZY" Output: 701 Constraints: 1 2020. 11. 22.
[leetcode 141] Linked List Cycle Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter. Return true if there is a cycle.. 2020. 11. 22.