Algorithms
-
LeetCode - 392. Is Subsequence [Kotlin]Algorithms/- LeetCode 2022. 9. 10. 03:51
문제 링크 : https://leetcode.com/problems/is-subsequence/ Is Subsequence - 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 정답(Solution) class Solution { fun isSubsequence(s: String, t: String): Boolean { var sIndex = 0 for(i in 0 until t.length){ if(sIndex < s.length && s[sIndex] == t[..
-
LeetCode - 205. Isomorphic Strings [Kotlin]Algorithms/- LeetCode 2022. 9. 7. 01:23
문제 링크 : 205. Isomorphic Strings Isomorphic Strings - 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 정답(Solution) class Solution { fun isIsomorphic(s: String, t: String): Boolean { val sKeyMap = HashMap() val tKeyMap = HashMap() for(i in s.indices){ val sValue : Char? = sKeyMap[s[i..
-
LeetCode - 724. Find Pivot Index [Kotlin]Algorithms/- LeetCode 2022. 9. 5. 11:00
문제 링크 : https://leetcode.com/problems/find-pivot-index/ Find Pivot Index - 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 정답 (Solution) class Solution { fun pivotIndex(nums: IntArray): Int { val totalSum = nums.sum() var leftSum = 0 for(i in 0 until nums.size){ if(leftSum == (tota..
-
LeetCode - 1480. Running Sum of 1d Array [Kotlin]Algorithms/- LeetCode 2022. 8. 2. 10:30
문제 링크 : 1480. Running Sum of 1d Array Running Sum of 1d Array - 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 정답 ( Solution ) class Solution { fun runningSum(nums: IntArray): IntArray { for(i in 1 until nums.size){ nums[i] += nums[i-1] } return nums } }
-
LeetCode - Trim a Binary Search Tree [Java]Algorithms/- LeetCode 2022. 4. 16. 00:59
문제 링크 : Trim a Binary Search Tree Trim a Binary 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 정답(Solution) class Solution { public TreeNode trimBST(TreeNode root, int low, int high) { if (root == null) return root; if (root.val > high) return trimBST(root.left, low,..
-
LeetCode - Binary Tree Postorder Traversal [Java]Algorithms/- LeetCode 2022. 4. 16. 00:18
문제 링크 : Binary Tree Postorder Traversal Binary Tree Postorder Traversal - 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 정답(Solution) 재귀풀이 import java.util.*; class Solution { public List postorderTraversal(TreeNode root) { List answer = new ArrayList(); dfs(root, answer); return ..
-
프로그래머스 - 올바른 괄호의 갯수 [자바]Algorithms/- 프로그래머스 2022. 3. 15. 23:07
문제 링크 : 올바른 괄호의 갯수 코딩테스트 연습 - 올바른 괄호의 갯수 올바른 괄호란 (())나 ()와 같이 올바르게 모두 닫힌 괄호를 의미합니다. )(나 ())() 와 같은 괄호는 올바르지 않은 괄호가 됩니다. 괄호 쌍의 개수 n이 주어질 때, n개의 괄호 쌍으로 만들 수 있는 모 programmers.co.kr 정답(Solution) import java.util.*; class Solution { private class P { int open, close; P(int open, int close){ this.open = open; this.close = close; } } public int solution(int n) { int answer = 0; Stack st = new Stack(); ..
-
프로그래머스 - 게임 맵 최단거리 [자바]Algorithms/- 프로그래머스 2022. 3. 15. 22:54
문제 링크 : 게임 맵 최단거리 코딩테스트 연습 - 게임 맵 최단거리 [[1,0,1,1,1],[1,0,1,0,1],[1,0,1,1,1],[1,1,1,0,1],[0,0,0,0,1]] 11 [[1,0,1,1,1],[1,0,1,0,1],[1,0,1,1,1],[1,1,1,0,0],[0,0,0,0,1]] -1 programmers.co.kr 정답(Solution) import java.util.*; class Solution { private class Position { int x, y; Position(int x, int y){ this.x = x; this.y = y; } } public int solution(int[][] maps) { int height = maps.length; int width = ..