Algorithm/java tip
-
21. Merge Two Sorted ListsAlgorithm/java tip 2021. 3. 13. 16:29
leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - 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 ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode ret = null; if(l1 == null) return l2; if(l2 == null) return l1; if(l1.val < l2...
-
530. Minimum Absolute Difference in BSTAlgorithm/java tip 2021. 3. 13. 15:41
leetcode.com/problems/minimum-absolute-difference-in-bst/ Minimum Absolute Difference in BST - 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 /* Tree의 value들 간에 차이가 가장 작은 값 Tree 순회 - prenoder : self, left, right - inorder : left, self, right - postorder : left, right, self 이진트리의 성..
-
589. N-ary Tree Preorder TraversalAlgorithm/java tip 2021. 3. 13. 11:39
leetcode.com/problems/n-ary-tree-preorder-traversal/ N-ary Tree Preorder 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 /* 자손이 N개인 트리의 pre-order */ class Solution { public List preorder(Node root) { List ret = new ArrayList(); traverse(root, ret); return ret; } public ..
-
78. SubsetsAlgorithm/java tip 2021. 3. 7. 00:40
leetcode.com/problems/subsets/ Subsets - 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 { List ret = new ArrayList(); public List subsets(int[] nums) { List subset = new ArrayList(); BT(nums, 0, subset); return ret; } public void BT(int[] nums, int index, List subse..
-
404. Sum of Left LeavesAlgorithm/java tip 2021. 3. 6. 22:10
leetcode.com/problems/sum-of-left-leaves/ Sum of Left Leaves - 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 a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * ..
-
22. Generate ParenthesesAlgorithm/java tip 2021. 3. 6. 21:55
leetcode.com/problems/generate-parentheses/ Generate Parentheses - 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 { int max; List ans = new ArrayList(); public List generateParenthesis(int n) { max = n; back_track(0, 0, ""); return ans; } public void back_track(int ..
-
559. Maximum Depth of N-ary TreeAlgorithm/java tip 2021. 3. 6. 21:48
leetcode.com/problems/maximum-depth-of-n-ary-tree/ Maximum Depth of N-ary 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 class Solution { public int maxDepth(Node root) { if(root == null) return 0; Queue q = new LinkedList(); q.offer(root); int depth = 0; while(!q.isEmpty()..
-
[programmers] 가장 먼 노드Algorithm/java tip 2021. 3. 6. 17:50
programmers.co.kr/learn/courses/30/lessons/49189 코딩테스트 연습 - 가장 먼 노드 6 [[3, 6], [4, 3], [3, 2], [1, 3], [1, 2], [2, 4], [5, 2]] 3 programmers.co.kr import java.util.*; class Solution { public int solution(int n, int[][] edge) { int[] dist = new int[n+1]; boolean[][] mat = new boolean[n + 1][n + 1]; for(int[] pair : edge) { mat[pair[0]][pair[1]] = mat[pair[1]][pair[0]] = true; } Queue q = new Link..