본문 바로가기

알고리즘45

[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.
array partition https://leetcode.com/problems/array-partition/ LeetCode - The World's Leading Online Programming Learning Platform 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 Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the su.. 2023. 9. 30.
Leet Code 412 public List fizzBuzz(int n) { if (n==0) { return Collections.emptyList(); } List answer = new ArrayList(); for (int i = 1; i "FizzBuzz"; case 3, 6, 9, 12 -> "Fizz"; case 5, 10 -> "Buzz"; default -> String.valueOf(index); }; } @Override public int size() { return n; } }; } } 이거 뭐임? 진짜 뭐임? 2023. 7. 25.
728x90