From 791bceba5aa8b55a0f118e82d906d200e3f63146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:49:39 +0900 Subject: [PATCH 1/2] Create Code Testcase Testcase Test Result 543. Diameter of Binary Tree.java --- ... Result 543. Diameter of Binary Tree.java" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/Code Testcase Testcase Test Result 543. Diameter of Binary Tree.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/Code Testcase Testcase Test Result 543. Diameter of Binary Tree.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/Code Testcase Testcase Test Result 543. Diameter of Binary Tree.java" new file mode 100644 index 00000000..75fdd08f --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/Code Testcase Testcase Test Result 543. Diameter of Binary Tree.java" @@ -0,0 +1,21 @@ +// 재귀함수 +// O(n) + +class Solution { + int max; + public int diameterOfBinaryTree(TreeNode root) { + max = 0; + depth(root); + return max; + } + + int depth(TreeNode node) { + if (node == null) return 0; + + int left = depth(node.left); + int right = depth(node.right); + max = Math.max(max, left + right); + + return Math.max(left, right) + 1; + } +} From 68d25251746ff028f9321564766c1cff34a18c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=97=BC=ED=98=9C=EC=A0=95?= <122238744+cyzlcyzl@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:50:28 +0900 Subject: [PATCH 2/2] Create 1219. Path with Maximum Gold.java --- .../1219. Path with Maximum Gold.java" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "leetcode3/\354\227\274\355\230\234\354\240\225/1219. Path with Maximum Gold.java" diff --git "a/leetcode3/\354\227\274\355\230\234\354\240\225/1219. Path with Maximum Gold.java" "b/leetcode3/\354\227\274\355\230\234\354\240\225/1219. Path with Maximum Gold.java" new file mode 100644 index 00000000..701ca698 --- /dev/null +++ "b/leetcode3/\354\227\274\355\230\234\354\240\225/1219. Path with Maximum Gold.java" @@ -0,0 +1,34 @@ +// dfs + 백트래킹 + +class Solution { + int[] dx = {-1, 1, 0, 0}; + int[] dy = {0, 0, -1, 1}; + + public int getMaximumGold(int[][] grid) { + int max = 0; + for (int i = 0; i=grid.length || y>=grid[0].length + || grid[x][y] == 0) return 0; + + int temp = grid[x][y]; + grid[x][y] = 0; + + int max = 0; + for (int i = 0; i<4; i++) { + max = Math.max(max, dfs(grid, x+dx[i], y+dy[i])); + } + grid[x][y] = temp; + + return max + temp; + } + +}