목록분류 전체보기 (943)
넘치게 채우기
작게 만들어라 함수를 만드는 첫 번째 규칙은 ‘작게!’ 입니다. 함수를 만드는 둘째 구칙은 ‘더 작게!’ 입니다. 함수에서의 들여쓰기 수준은 1단이나 2단을 넘어서면 읽기 매우 힘들어집니다. 한 함수에 많은 중첩 구조가 들어가지 않도록 해야합니다. 한 가지만 해라 “함수는 한 가지를 해야 한다. 그 한가지를 잘 해야 한다. 그 한가지만을 해야 한다.” 우리가 함수를 만드는 이유는 큰 개념을 다음 추상화 수준에서 여러 단계로 나눠 수행하기 위함입니다. 함수 당 추상화 수준은 하나로 함수가 확실히 ‘한 가지’ 작업만 하려면 함수 내 모든 문장의 추상화 수준이 동일해야 합니다. 한 함수 내에 추상화 수준을 섞으면 코드를 읽는 사람이 헷갈립니다. 특정 표현이 근본 개념인지 세부사항인지 구분하기가 어려워집니다. ..
https://leetcode.com/problems/candy/description/?envType=study-plan-v2&envId=top-interview-150 Candy - LeetCode Can you solve this real interview question? Candy - There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings. You are giving candies to these children subjected to the following requirements: * Each leetcode.com 문제 유형 : 그리디 문제 난이..
https://leetcode.com/problems/product-of-array-except-self/?envType=study-plan-v2&envId=top-interview-150 Product of Array Except Self - LeetCode Can you solve this real interview question? Product of Array Except Self - Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix o..
소프트웨어에서 이름은 어디나 쓰입니다. 우리는 변수, 함수, 인수, 클래스, 패키지, 파일과 폴더 등 모두 이름을 붙입니다. 이렇게 많이 쓰이는 이름을 처음에 한 번 잘지으면 앞으로의 개발이 편해집니다. 의도를 분명히 밝혀라 좋은 이름을 만드는데에는 시간이 걸릴 수 있으나, 그로인해 앞으로 절약될 시간은 더 큽니다. 개발을 하다가도, 더 나은 이름이 생각나면 모두 바꾸십시오. 변수나 함수, 클래스의 이름은 존재 이유 수행 기능 사용 방법 을 주석 없이 표현할 수 있어야 합니다. int d; // 경과 시간(단위: 날짜) 보다 int elapsedTimeInDays; int daysSinceCreation; 와 같이 의도가 드러나는 이름을 사용하면 코드 이해와 변경이 쉬워집니다. 그릇된 정보를 피하라 널리..
ios_base::sync_with_stdio(false); cin.tie(null); ios_base::sync_with_stdio(false)는 C++의 iostream과 C의 stdio의 동기화를 끊습니다. 기본적으로 C++의 iostream은 C 스타일의 입출력과 동기화되도록 설계되어 있어서 C스타일의 입출력 함수도 같이 사용되는 경우가 많습니다. 이 동기화 과정에서 속도저하가 발생합니다. cin.tie(null)은 cin과 cout이 동기화되지 않도록 설정합니다. 기본적으로 cin은 cout과 묶여서 작업이 있을 때마다 출력 버퍼를 비우는 작업이 수행되는데, 이 동기화를 막으면 더 빨리 작업이 실행됩니다. 알고리즘 문제를 푸는 데에는 매우 빠르게 활용할 수 있습니다.
https://leetcode.com/problems/peak-index-in-a-mountain-array/description/ Peak Index in a Mountain Array - LeetCode Can you solve this real interview question? Peak Index in a Mountain Array - An array arr a mountain if the following properties hold: * arr.length >= 3 * There exists some i with 0 < i < arr.length - 1 such that: * arr[0] < arr[1] < ... < arr[i - 1] < arr leetcode.com 문제 유형 : 배열 문..
https://leetcode.com/problems/insert-delete-getrandom-o1/description/ Insert Delete GetRandom O(1) - LeetCode Can you solve this real interview question? Insert Delete GetRandom O(1) - Implement the RandomizedSet class: * RandomizedSet() Initializes the RandomizedSet object. * bool insert(int val) Inserts an item val into the set if not present. Returns true if th leetcode.com 문제 유형 : OOP / 배열 문..
https://leetcode.com/problems/powx-n/description/ Pow(x, n) - LeetCode Can you solve this real interview question? Pow(x, n) - Implement pow(x, n) [http://www.cplusplus.com/reference/valarray/pow/], which calculates x raised to the power n (i.e., xn). Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Inpu leetcode.com 문제 유형 : 수학 문제 난이도 : Medium 문제 Implement pow(x, n), which cal..
나쁜 코드를 치르는 대가 나쁜 코드는 개발 속도를 크게 떨어뜨린다. 매번 얽히고설킨 코드를 ‘해독’해서 얽히고설킨 코드를 더한다. 시간이 지나면서 쓰레기 더미는 점점 높아지고 깊어지고 커진다. 나쁜 코드가 쌓일수록 생산성을 떨어지고, 0에 가까워진다. 나쁜 코드는 엉망으로 유지시키고, 기한 내로 프로젝트를 완성하지 못하게 한다. 빨리 나아가는 유일한 방법은 코드를 최대한 깨끗하게 유지하는 습관이다. 깨끗한 코드란? 깨끗한 코드는 다른 사람들도 쉽게 읽을 수 있을 정도로 이해하고 수정하기 쉬우며, 버그가 적고 유지보수가 용이한 코드를 말한다. 책 속에는 소프트웨어 업계의 대부들이 생각하는 깨끗한 코드들에 대한 각자의 생각이 담겨있다. 우리는 코드를 짜는 시간보다 들여다보는 시간이 많다. 대부분은 코딩을 하..
https://leetcode.com/problems/h-index/description/?envType=study-plan-v2&envId=top-interview-150 H-Index - LeetCode Can you solve this real interview question? H-Index - Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index. According to the definition of h-index on W leetcode.com 문제 유형 : 배열 문..