반응형
반응형
문제 주어진 문제는 Tribonacci 수열에서 n번째 항의 값을 구하는 것입니다. Tribonacci 수열은 이전 3개의 항을 더한 값으로 다음 항을 계산하는 특징을 가지고 있습니다. 풀이 주어진 문제를 해결하기 위해 다이나믹 프로그래을 활용할 수 있습니다. 다이나믹 프로그래밍은 중복되는 계산을 피하기 위해 계산 결과를 저장하여 재활용하는 기법입니다. Tribonacci 수열의 n번째 항의 값을 구하기 위해 다음과 같은 접근 방식을 사용합니다: 초기값 설정: dp 리스트를 생성하고 초기값으로 dp[0] = 0, dp[1] = 1, dp[2] = 1을 설정합니다. 반복문을 통한 값 계산: dp[i] = dp[i-3] + dp[i-2] + dp[i-1]을 반복문을 통해 계산하여 dp[n]의 값을 구합니다...
문제 Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] Note: All inputs will be in lowercase. The order of your output does not matter. 풀이 Anagram 은 단어나 문장을 구성하고 있는 문자의 순서를 바꾸어 다른 단어나 문장을 만드는 놀이이다. 주어진 input에서 Anagram 인 것들만 모아주면 되는 문제이다. input이 모두 소문자이기 떄문에 대소문자를 구분할 필요가 없다. map를 이..
문제 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom. Example : Consider the following matrix: ] Given target = 5, return true. Given target = 20, return false. 풀이 주어진 matrix에서 target 값이 존재하는 지를 찾는 문..