본문 바로가기

자바461

[LeetCode/Java] 383. Ransom Note -Codeclass Solution { public boolean canConstruct(String ransomNote, String magazine) { Map map = new HashMap(); for (char c : magazine.toCharArray()) { map.put(c, map.getOrDefault(c, 0) + 1); } for (char c2 : ransomNote.toCharArray()) { Integer c2_cnt = map.get(c2); c2_cnt = (c2_cnt == null ? 0 : c2_cnt) - 1; if (c2_cnt 2025. 6. 10.
[LeetCode/Java] 876. Middle of the Linked List -Code/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */class Solution { public ListNode middleNode(ListNode head) { List nums = new ArrayList(); int len = 0; while(head != nu.. 2025. 6. 10.
[LeetCode/Java] 1342. Number of Steps to Reduce a Number to Zero -Codeclass Solution { public int numberOfSteps(int num) { int answer = 0; while(num > 0) { answer++; if (num % 2 == 0) { num /= 2; } else { num--; } } return answer; }} 2025. 6. 10.
[LeetCode/Java] 412. Fizz Buzz -Codeclass Solution { public List fizzBuzz(int n) { List answer = new ArrayList(); for (int i = 1; i 2025. 6. 10.
[LeetCode/Java] 1672. Richest Customer Wealth -Codeclass Solution { public int maximumWealth(int[][] accounts) { int wealth = 0; for ( int[] customer : accounts ){ wealth = Math.max (wealth , Arrays.stream(customer).sum()); } return wealth; }} 2025. 6. 10.
[LeetCode/Java] 2236. Root Equals Sum of Children -Code/** * 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 checkTree(Tre.. 2025. 6. 10.