알고리즘/LeetCode

    [LeetCode] Reverse Linked List (Java)

    ✉️문제 https://leetcode.com/problems/reverse-linked-list/description/ Reverse Linked List - LeetCode Can you solve this real interview question? Reverse Linked List - Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: [https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg] Input: head = [1,2,3,4,5] O leetcode.com 🗝 문제풀이 public class ReverseLinke..

    [LeetCode] Longest Consecutive Sequence (Java)

    ✉️문제 https://leetcode.com/problems/longest-consecutive-sequence/description/ Longest Consecutive Sequence - LeetCode Can you solve this real interview question? Longest Consecutive Sequence - Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Example 1: Input: leetcode.com 📝 접근 Set 배열에 모든 배..

    [LeetCode] House Robber II (Java)

    ✉️문제 https://leetcode.com/problems/house-robber-ii/description/ House Robber II - LeetCode Can you solve this real interview question? House Robber II - You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first hou leetcode.com 📝 접근 원형으로 돌기 때문에 House Robber I보다 조금 ..

    [LeetCode] Combination Sum IV (Java)

    ✉️문제 https://leetcode.com/problems/combination-sum-iv/description/ Combination Sum IV - LeetCode Can you solve this real interview question? Combination Sum IV - Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target. The test cases are generated so that the answer can fi leetcode.com 📝 접근 전형적인 DP 알고리즘 문제이다. 이전 경우의 수..

    [LeetCode] Word Break (Java)

    ✉️문제 https://leetcode.com/problems/word-break/description/ Word Break - LeetCode Can you solve this real interview question? Word Break - Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may leetcode.com 📝 접근 기본적인 아이디어는 wordDict안에 들어있는 word의 길이 만큼 문자열..