-
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 ..
-
[우아콘2020] 수십억건에서 QUERYDSL 사용하기Working 2021. 3. 8. 14:13
www.youtube.com/watch?v=zMAX7g6rO_Y 1. 워밍업 - extends, implements 사용하지 않기 -> 대신 QueryDslRepositorySupport 상속, JPAQueryFactory 빈 등록 -> JpaQueryFactory만 있으면 QueryDsl은 사용할 수 있다! - 동적 쿼리 -> 어떤 쿼리인지 예상하기 어렵다 -> BooleanExpression - null 반환시 자동으로 조건에서 제거된다. 2. 성능개선 - SELECT - querydsl exist 금지 - exist는 조건에 부합하는 row 1개만 찾으면 바로 쿼리 종료 하지만 count는 끝까지 찾는다 - querydsl의 exist는 내부적으로 count를 사용 - 실제로 구현해보자! - lim..
-
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..
-
[programmers] 큰 수 만들기Algorithm/java tip 2021. 3. 6. 16:21
programmers.co.kr/learn/courses/30/lessons/42883 코딩테스트 연습 - 큰 수 만들기 programmers.co.kr class Solution { public String solution(String number, int k) { int resultLen = number.length() - k;// 결과 길이 StringBuilder result = new StringBuilder(); int maxi = -1; for(int i=0; i max) { max = val; maxi = j; } } result.append(number.charAt(maxi)); } return result.toString(); } }