문제풀이 2021 03 01
2021.03.01 연습
- 사용언어 : java
/**
* 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 int rangeSumBST(TreeNode root, int low, int high) {
int sum = 0;
if (root == null) return 0;
if (root.val >= low && root.val <= high) { sum += root.val; }
int left = rangeSumBST(root.left, low, high);
int right = rangeSumBST(root.right, low, high);
return sum + left + right;
}
}
Runtime: 1 ms, faster than 52.81% of Java online submissions for Range Sum of BST. Memory Usage: 47.2 MB, less than 42.83% of Java online submissions for Range Sum of BST.
- 사용언어 : java
class Solution {
public int minTimeToVisitAllPoints(int[][] points) {
int count = 0;
for ( int i = 0; i < points.length-1; i++ ) {
count += Math.max((int)Math.abs(points[i+1][0] - points[i][0]), (int)Math.abs(points[i+1][1] - points[i][1]));
}
return count;
}
}
Runtime: 0 ms, faster than 100.00% of Java online submissions for Minimum Time Visiting All Points. Memory Usage: 38.9 MB, less than 23.78% of Java online submissions for Minimum Time Visiting All Points.