随笔分类 - leetcode 每日一题
摘要:leetcode 每日一题 1470. 重新排列数组 class Solution { public int[] shuffle(int[] nums, int n) { int[] arr = new int[nums.length]; for (int i = 0; i < nums.lengt
阅读全文
摘要:leetcode 每日一题 1302. 层数最深叶子节点的和 //给你一棵二叉树的根节点 root ,请你返回 层数最深的叶子节点的和 。 // // // // 示例 1: // // // // //输入:root = [1,2,3,4,5,null,6,7,null,null,null,nul
阅读全文
摘要:leetcode 每日一题 515. 在每个树行中找最大值 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeN
阅读全文
摘要:leetcode 每日一题 513. 找树左下角的值 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode
阅读全文
摘要:leetcode 每日一题 1108. IP 地址无效化 1. replaceAll 字符串替换,支持正则表达式 class Solution { public String defangIPaddr(String address) { return address.replaceAll("\\."
阅读全文
摘要:leetcode 每日一题 1089. 复写零 func duplicateZeros(arr []int) { for i := 0; i < len(arr); i++ { if arr[i] != 0 { continue } for j := len(arr) - 2 ; j > i ; j
阅读全文
摘要:leetcode 每日一题 926. 将字符串翻转到单调递增 func minFlipsMonoIncr(s string) int { var dp0,dp1 int for _,data := range s { i := int(data) dp1 = min(dp0,dp1) + ('1'
阅读全文
摘要:leetcode 每日一题 1051. 高度检查器 import ( "sort" ) func heightChecker(heights []int) int { var num = 0 src := heights dst := make([]int, len(src)) copy(dst,
阅读全文
摘要:leetcode 每日一题 1037. 有效的回旋镖 百度搜了个两点一线方程公式,然后把3个点带入计算,一直出错,后来发现公式错误,用go语言自己写了个简单的判断 func isBoomerang(points [][]int) bool { ax,ay := points[0][0],points
阅读全文
摘要:leetcode 每日一题 464. 我能赢吗 class Solution { Map<Integer, Boolean> memo = new HashMap<Integer, Boolean>(); public boolean canIWin(int maxChoosableInteger,
阅读全文
摘要:leetcode 每日一题 450. 删除二叉搜索树中的节点 class Solution { public TreeNode deleteNode(TreeNode root, int key) { if(root == null){ return null; } if(key == root.v
阅读全文
摘要:leetcode 每日一题 473. 火柴拼正方形 class Solution { int ave = 0; int num = 4; public boolean makesquare(int[] matchsticks) { int sum = 0; for (int matchstick :
阅读全文
摘要:leetcode 每日一题 1022. 从根到叶的二进制数之和 class Solution { int sum = 0; public int sumRootToLeaf(TreeNode root) { f(root, 0); return sum; } private void f(TreeN
阅读全文
摘要:leetcode 每日一题 965. 单值二叉树 class Solution { public boolean isUnivalTree(TreeNode root) { if (root == null) { return true; } if(root.left != null && root
阅读全文
摘要:leetcode 每日一题 462. 最少移动次数使数组元素相等 II class Solution { public int minMoves2(int[] nums) { Arrays.sort(nums); int num = nums[nums.length / 2]; int res =
阅读全文
摘要:leetcode 每日一题 953. 验证外星语词典 class Solution { public boolean isAlienSorted(String[] words, String order) { char[] chars = order.toCharArray(); int[] arr
阅读全文
摘要:leetcode 每日一题 面试题 04.06. 后继者 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNo
阅读全文
摘要:leetcode 每日一题 面试题 01.05. 一次编辑 class Solution { public boolean oneEditAway(String first, String second) { char[] a = first.toCharArray(); char[] b = se
阅读全文
摘要:leetcode 每日一题 944. 删列造序 class Solution { public int minDeletionSize(String[] strs) { int num = 0; for (int j = 0; j < strs[0].length(); j++) { char bu
阅读全文
摘要:leetcode 每日一题 942. 增减字符串匹配 class Solution { public int[] diStringMatch(String s) { int[] arr = new int[s.length()+1]; int l = 0; int r = s.length(); f
阅读全文