본문 바로가기

전체 글163

[LeetCode] 94. Binary Tree Inorder Traversal class Solution { public List inorderTraversal(TreeNode root) { List answer = new ArrayList(); Stack stack = new Stack(); if (root == null) { return answer; } TreeNode current = root; while(current != null || !stack.isEmpty()) { while (current != null) { stack.push(current); current = current.left; } current = stack.pop(); answer.add(current.val); current = current.right; } return answer; } } Ino.. 2023. 12. 5.
[LeetCode] 111. Minimum Depth of Binary Tree class Solution { public int minDepth(TreeNode root) { if (root == null) { return 0; } Queue queue = new LinkedList(); queue.offer(root); int level = 1; while (!queue.isEmpty()) { int size = queue.size(); for (int i = 0; i < size; i++) { TreeNode curNode = queue.poll(); if (curNode.left == null && curNode.right == null) { return level; } if (curNode.left != null) { queue.offer(curNode.left); } if.. 2023. 12. 5.
[LeetCode] 110. Balanced Binary Tree class Solution { public boolean isBalanced(TreeNode root) { if (root == null) { return true; } if (isBalancedHelper(root) == -1) { return false; } return true; } public int isBalancedHelper(TreeNode root) { if (root == null) { //해당 노드가 null 이라면 0을 반환 return 0; } int leftDepth = isBalancedHelper(root.left); //왼쪽 줄기의 깊이를 계산 int rightDepth = isBalancedHelper(root.right); // 오른쪽 줄기의 깊이를 계산 if (leftD.. 2023. 12. 5.
[LeetCode] 104. Maximum Depth of Binary Tree class Solution { public int maxDepth(TreeNode root) { if (root == null) { //해당 노드가 null 이라면 0을 반환 return 0; } int leftDepth = maxDepth(root.left); //왼쪽 줄기의 깊이를 계산 int rightDepth = maxDepth(root.right); // 오른쪽 줄기의 깊이를 계산 return Math.max(leftDepth, rightDepth) + 1; // 왼쪽과 오른쪽 중 더 큰쪽에 1을 더하여 반환 } } 우선 왼쪽부터 시작하여 가장 깊은 곳에 위치한 node까지 찾아간다. 거기서부터 차례대로 올라가며 깊이 값에 1을 더해간다. 1번 루트노드에서 시작하여 maxDepth(root.le.. 2023. 12. 5.
[LeetCode] 101. Symmetric Tree class Solution { public boolean isSymmetric(TreeNode root) { if (root == null) { return true; //최상위 노드가 null 이라면 true 반환 } return isSymmetricHelper(root.left, root.right); //추가 메서드 생성하여 좌측 우측 노드 전달 } public boolean isSymmetricHelper(TreeNode p, TreeNode q) { if (p == null || q == null) { return p == q; // 두 노드중 하나가 null 이라면 두 노드를 비교한 값을 반환 } if (p.val != q.val) { return false; // 두 노드의 값이 다르다면 f.. 2023. 12. 5.
[LeetCode] 100. Same Tree /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode right) { * this.val = val; * this.left = left; * this.right = right; * } * } */ class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if (p == null && q == null) { return.. 2023. 12. 4.
토비의 스프링 부트 스프링 컨테이너는 크게 두가지가 필요하다. 1. 우리의 비즈니스 로직을 담고 있는 애플리케이션 코드 2. 이러한 코드들로 애플리케이션을 어떤 식으로 구성할지에 대한 정보를 담고 있는 Configuration Metadata. 스프링 컨테이너가 내부에서 위 두가지를 조합하여 내부에 Bean이라 불리는 오브젝트들을 구성하여 Server Application으로 만든다. 스프링 컨테이너에 HelloController를 집어넣고, 그 컨트롤러를 직접 생성하는 것이 아닌, 스프링 컨테이너에 요청을 하여 가져온 다음 사용하는 방식 스프링 컨테이너를 대표하는 인터페이스 ApplicationContext가 있는데 스프링 컨테이너의 역할을 한다. 스프링 컨테이너는 오브젝트를 직접 넣어 설정할 수도 있지만, 어떤 클래스를.. 2023. 11. 28.
1장 비즈니스 코드를 기술코드로부터 분리한다고 하는데 비즈니스 코드는 무엇이고 기술 코드는 무엇인가 비즈니스 규칙을 도메인 핵사곤에 캡슐화 했다고 하는데 그 뜻이 무엇인가. 그전에, 비즈니스 규칙이란 무엇인가 유스케이스와 입력포트, 출력포트의 관계는 Service-ServiceImpl 관계로 보이는데 무언가 차이가 있는건가? 출력포트를 통해 외부 데이터를 받는다. -> 외부로부터 데이터를 출력 받는다는 의미? 도메인 헥사곤 실제 세상의 문제를 이해하고 모델링하는 활동을 나타냄 기술에 구애받지 않는 형태로 표현되어야 함 중요 비즈니스 데이터와 규칙 관련 엔티티들이 있는데 이들이 실제 문제에 대한 모델을 나타냄 엔티티와 값객체로 구분될 수 있음. 애플리케이션 핵사곤 애플리케이션 특화 작업을 추상적으로 처리하는 곳.. 2023. 11. 27.
그래서 @Retention이 뭔데 이 개발자야 왜 @Retention이 궁금해졌는가 자바 Annotation을 뒤적거리다가 @Retention을 보게 되었는데 각각 Class, Source, Runtime 세가지 종류로 나뉘어 있는걸 보았다. 그리고 이게 도대체 뭔데.. 싶어서 찾아보기 시작했다. 그래서 우선 Annotation이 뭔가요? 어노테이션은 클래스, 메서드 혹은 필드에 선언할 수 있는 일종의 주석같은 것 이라고 설명할 수 있을 것 같다. 그러면 Annotation의 역할은 뭔가요? Annotation은 JVM이나 컴파일러에 추가적인 정보, metadata를 전달하는 역할을 담당합니다. 컴파일 시점, 런타임 시점, 혹은 빌드시에 참고할 정보를 가지고 있습니다. 그럼 본론으로 돌아와서 @Retention이 뭔가요? https://docs.or.. 2023. 11. 26.
728x90