본문 바로가기

Leetcode 100문제 도전

(32)
[Leetcode 8/100] Letter Tile Possibilities - Medium https://leetcode.com/problems/letter-tile-possibilities/ Letter Tile Possibilities - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 백트래킹 문제로 DFS를 이용해 조합을 구하면 되는 문제입니다. 이런 유형의 문제는 쉽게 접해볼 수 있었는데 문자열을 다루는 부분이 조금 어려웠습니다. StringBuilder의 setLength 함수를 통해 원래의 문자열로 되돌려주는 부분이 가장 중요했던 것 같습니..
[Leetcode 7/100] Increasing Order Search Tree - Easy https://leetcode.com/problems/increasing-order-search-tree/ Increasing Order Search Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 이진탐색트리를 왼쪽 노드의 자식은 없고 오른쪽 노드의 자식만 존재하도록 트리를 순서대로 정렬하는 문제입니다. 이진탐색트리의 특징은 모든 노드의 왼쪽 노드의 값은 루트 노드보다 작으며 오른쪽 노드의 값은 루트 노드의 값 보다 큰 것입니다. 이 특징을 ..
[Leetcode 6/100] Same Tree - Easy https://leetcode.com/problems/same-tree/ Same Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 두 개의 트리 노드를 input으로 받아서 동일한 트리 노드인지 체크하는 문제입니다. 트리를 탐색하기 위해 DFS 방식을 떠올려서 DFS로 풀이했습니다. 처음에는 한 개의 트리마다 DFS를 통해 방문한 노드를 배열에 담아 반환하는 매서드를 만든 후에 두 개의 배열을 비교하는 방식을 생각했는데 제네릭을 Integer로 선언한..
[Leetcode 5/100] Roman to Integer - Easy https://leetcode.com/problems/roman-to-integer/submissions/ Roman to Integer - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 class Solution { public int romanToInt(String s) { int pre = RomanToInteger(s.charAt(s.length()-1)); int answer = pre; for(int i=s.length()-2; i>=0; i--..
[Leetcode 4/100] Palindrome Number - Easy https://leetcode.com/problems/palindrome-number/ Palindrome Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열로 푸는 방식 class Solution { public boolean isPalindrome(int x) { String str = String.valueOf(x); for(int i=0; i
[Leetcode 3/100] Reverse Integer - Easy https://leetcode.com/problems/reverse-integer/ Reverse Integer - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열로 푸는 방식 class Solution { public int reverse(int x) { String reversed = new StringBuilder().append(Math.abs(x)).reverse().toString(); try{ return ( x < 0 ) ? Integer.p..
[Leetcode 2/100] Add Two Numbers - Medium https://leetcode.com/problems/add-two-numbers/ Add Two Numbers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com (다시 풀기) /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode..
[Leetcode 1/100] Two Sum - Easy https://leetcode.com/problems/two-sum/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 난이도 : Easy 난이도 easy 문제로 문제를 보자마자 바로 브루트포스 방식으로 풀었습니다. 솔루션에는 시간복잡도가 O(n)으로 해쉬 맵을 활용한 인상적인 풀이가 있어서 공유합니다. 내 풀이 class Solution { public int[] twoSum(int[] nums, int target) { int[] arr = n..