반응형
SMALL

분류 전체보기 130

[LeetCode] DP, String - 5. Longest Palindromic Substring

문제 Given a string s, return the longest palindromic substring in s. A string is called a palindrome string if the reverse of that string is the same as the original string. Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Constraints: 1 = 0 && y < s.length && s[x] === s[y]) { x--; y++; } // 만약 x가 -1 일 때, 혹은 만약 y가 s.l..

Coding Interview 2022.10.03

[기타] 코딩테스트에 활용되는 수학 이론

최대공약수와 최소공백수 최대공약수 // 유클리드 호제법 const gcd = (a, b) => { if(a % b === 0) { return b; } return gcd(b, a % b) }; // 반복문 const gcd = (a, b) => { // 큰 걸 작은 걸로 나누고 // 깔끔히 안나뉘었으면 // 작은걸 => 큰걸로 / 나눈나머지 => 작은걸로 다시 재조정해서 // 깔끔하게 나뉠 때 까지 반복 후 => 나머지가 없을 때 작은 값을 최대공약수로 한다 while(a % b !== 0) { [a, b] = [b, a % b] } return b; } 최대공배수 // 최소공배수 = (a * b) / 최대공약수 const gcd = (a, b) => { if(a % b === 0) { return b..

Coding Interview 2022.09.30

[LeetCode] DP - 279. Perfect Squares (feat. 라그랑주의 네제곱수)

문제 Given an integer n, return the least number of perfect square numbers that sum to n. A perfect square is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, 1, 4, 9, and 16 are perfect squares while 3 and 11 are not. Example 1: Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4. Example 2: Input: n = 13 Output: 2 Explanatio..

Coding Interview 2022.09.30
반응형
LIST