You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.
Given the integer n, return the number of complete rows of the staircase you will build.
이펙티브 코틀린 - 아이템 17. 이름 있는 아규먼트를 사용하라를 보다 이해가 되지 않은 코드가 있어서
필자처럼 코틀린을 찍먹 한 사람들에게 경각심을 불러일으키기 위해 글을 작성하고자 한다.
(사실은 스스로를 위해 정리를 하는 글이다.)
Kotlin에서 ImmutableList를 반환하는 listOf( )를 사용하여 재미난 실험을 해보자.
listOf( )가 반환하는 인스턴스를 강제로 MutableList로 Type Casting을 하고
그 인스턴스에 값을 추가하는 행위를 해보려고 한다.
Given a 2D matrix matrix, handle multiple queries of the following type:
Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
Implement the NumMatrix class:
NumMatrix(int[][] matrix) Initializes the object with the integer matrix matrix.
int sumRegion(int row1, int col1, int row2, int col2) Returns the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
You must design an algorithm where sumRegion works on O(1) time complexity.
Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.