Google 태그 관리자 아이콘
반응형

전체 글 177

.leetcode(979. Distribute Coins in Binary Tree)

https://leetcode.com/problems/distribute-coins-in-binary-tree/ 1. 2022.02.20 시도 소요시간: 76분(36분 구상, 40분 풀이) class Solution { public int distributeCoins(TreeNode root) { return traverse(root); } private int traverse(TreeNode root) { int left = 0; int leftv = 0; if (root.left != null) { left = traverse(root.left); leftv = root.left.val; } int right = 0; int rightv = 0; if (root.right != null) { righ..

알고리즘 풀이 2022.02.20

.leetcode(513. Find Bottom Left Tree Value)

https://leetcode.com/problems/find-bottom-left-tree-value/ 1. 2022.02.06 시도 소요시간: 18분(전역변수), 10분(bfs) // 전역변수 class Solution { private int maxDepth = -1; private int max = Integer.MIN_VALUE; public int findBottomLeftValue(TreeNode root) { dfs(root, 0); return max; } private void dfs(TreeNode root, int depth) { if (root == null) { return; } dfs(root.left, depth+1); dfs(root.right, depth+1); if (r..

알고리즘 풀이 2022.02.06

.leetcode(515. Find Largest Value in Each Tree Row)

https://leetcode.com/problems/find-largest-value-in-each-tree-row/ 1. 2022.01.30 시도 소요시간: 30분 이상(다른 일때문에 측정x) class Solution { public List largestValues(TreeNode root) { LinkedList output = new LinkedList(); if (root == null) { return output; } LinkedList queue = new LinkedList(); LinkedList depthQueue = new LinkedList(); queue.offer(root); depthQueue.offer(0); while(!queue.isEmpty()) { TreeNode..

알고리즘 풀이 2022.01.30
반응형