随笔分类 -  leetcode 每日一题

摘要:leetcode 每日一题 933. 最近的请求次数 class RecentCounter {​ private List<Integer> list;​ public RecentCounter() { list = new ArrayList<>(); }​ public int ping(i 阅读全文
posted @ 2022-05-06 09:31 java架构师1 阅读(28) 评论(0) 推荐(0)
摘要:leetcode 每日一题 713. 乘积小于 K 的子数组 瞎写,自己都不知道写的什么,缺了条件就补条件 class Solution { public int numSubarrayProductLessThanK(int[] nums, int k) { int end = 0; int su 阅读全文
posted @ 2022-05-05 10:49 java架构师1 阅读(19) 评论(0) 推荐(0)
摘要:leetcode 每日一题 427. 建立四叉树 class Solution { public Node construct(int[][] grid) {​ return f(grid, 0, 0, grid.length);​ }​ private Node f(int[][] grid, i 阅读全文
posted @ 2022-04-29 11:17 java架构师1 阅读(28) 评论(0) 推荐(0)
摘要:leetcode 每日一题 905. 按奇偶排序数组 class Solution { public int[] sortArrayByParity(int[] nums) { int i = 0; int j = nums.length - 1; while (i < j) { while (nu 阅读全文
posted @ 2022-04-28 09:30 java架构师1 阅读(19) 评论(0) 推荐(0)
摘要:leetcode每日一题 883. 三维形体投影面积 class Solution { public int projectionArea(int[][] grid) { int sum = 0; for (int i = 0; i < grid.length; i++) { int max = 0 阅读全文
posted @ 2022-04-26 10:39 java架构师1 阅读(31) 评论(0) 推荐(0)
摘要:leetcode每日一题 398. 随机数索引 class Solution {​ private int[] nums;​ public Solution(int[] nums) { this.nums = nums; } public int pick(int target) { List<In 阅读全文
posted @ 2022-04-25 11:03 java架构师1 阅读(21) 评论(0) 推荐(0)
摘要:leetcode每日一题 868. 二进制间距 class Solution { public int binaryGap(int n) { char[] arr = Integer.toBinaryString(n).toCharArray(); int[] res = new int[arr.l 阅读全文
posted @ 2022-04-24 08:51 java架构师1 阅读(22) 评论(0) 推荐(0)
摘要:leetcode每日一题 396. 旋转函数 1.暴力破解 超时 class Solution { public int maxRotateFunction(int[] nums) { if(nums.length == 1){ return 0; } int max = Integer.MIN_V 阅读全文
posted @ 2022-04-22 09:56 java架构师1 阅读(31) 评论(0) 推荐(0)
摘要:leetcode每日一题 388. 文件的最长绝对路径 1.先考虑各种情况,然后写公共情况,代码没优化,leetcode跑和本地测试结果不一样,没去往下做了 class Solution { public int lengthLongestPath(String input) { //不是目录的情况 阅读全文
posted @ 2022-04-20 20:07 java架构师1 阅读(25) 评论(0) 推荐(0)
摘要:leetcode每日一题 821. 字符的最短距离 1.普通双指针 class Solution { public int[] shortestToChar(String s, char c) { int[] result = new int[s.length()]; int l = 0; int 阅读全文
posted @ 2022-04-19 10:00 java架构师1 阅读(37) 评论(0) 推荐(0)
摘要:leetcode每日一题 386. 字典序排数 public List<Integer> lexicalOrder(int n) { List<Integer> list = new ArrayList<>(n); for (int i = 1; i < 10; i++) { f(list, n, 阅读全文
posted @ 2022-04-18 09:08 java架构师1 阅读(16) 评论(0) 推荐(0)
摘要:leetcode每日一题 1672. 最富有客户的资产总量 本地测试没问题,提交返回结果和本地测试不一致 class Solution { public NestedInteger deserialize(String s) { if(s.charAt(0) != '['){ return new 阅读全文
posted @ 2022-04-15 11:14 java架构师1 阅读(30) 评论(0) 推荐(0)
摘要:leetcode每日一题 1672. 最富有客户的资产总量 java8 解决 流比for循环慢,所以性能较低,int转Integer也存在性能损耗 class Solution { public int maximumWealth(int[][] accounts) { int[] max = ne 阅读全文
posted @ 2022-04-14 09:57 java架构师1 阅读(40) 评论(0) 推荐(0)
摘要:leetcode每日一题 380. O(1) 时间插入、删除和获取随机元素 class RandomizedSet {​ private Map<Integer,Integer> map; private List<Integer> list;​ public RandomizedSet() { m 阅读全文
posted @ 2022-04-13 10:07 java架构师1 阅读(34) 评论(0) 推荐(0)
摘要:leetcode每日一题 806. 写字符串需要的行数 class Solution { public int[] numberOfLines(int[] widths, String s) { int[] result = new int[2]; result[0] = 1; char[] arr 阅读全文
posted @ 2022-04-12 10:09 java架构师1 阅读(30) 评论(0) 推荐(0)
摘要:leetcode每日一题 357.统计各位数字都不同 方法1:暴力破解,遍历每一种可能 class Solution {​ public int countNumbersWithUniqueDigits(int n) { boolean[] buf = new boolean[10]; return 阅读全文
posted @ 2022-04-11 09:55 java架构师1 阅读(27) 评论(0) 推荐(0)
摘要:leetcode每日一题 429.N 叉树的层序遍历 简单的DFS遍历 class Solution { public List<List<Integer>> levelOrder(Node root) { if(root == null){ return new ArrayList<>(); } 阅读全文
posted @ 2022-04-08 15:26 java架构师1 阅读(17) 评论(0) 推荐(0)