import java.util.Arrays; public class Main { public static void main(String[] args) { int[] nums1 = {1, 2, 3, 4, 5, 6, 7}; int k1 = 3; rotate(nums1, k1); System.out.println("轮转后的数组:" + Arrays.toString(nums1)); // 输出:[5, 6, 7, 1, 2, 3, 4] int[] n...
class Solution: def maxNumber(self, nums1, nums2, k): def pick_max(nums, k): stack = [] drop = len(nums) - k for num in nums: while drop and stack and stack[-1] < num: stack.pop() drop -= 1 stack.append(num) return stack[:k] def merge(A, B): ans = [] while A...
publicclass Solution {public booleanisPowerOfThree(int n) {double res = Math.log(n)/Math.log(3);return Math.abs(res - Math.rint(res))<0.0000000001; } } 说明: 其实和上面一样用的是对数,这就更加直接了,通过求log3(n)的结果,看与其最近的整数的差值满足几乎为0即可。 Problem: Given a singl...
Reference:https://discuss.leetcode.com/topic/27504/my-concise-java-solution-based-on-bfs-and-dfs importjava.util.ArrayList;importjava.util.HashMap;importjava.util.LinkedList;importjava.util.List;importjava.util.Queue;importjava.util.Set;publicclassWordLadderII {publicList<List<String>> findLadders(...
.prettierrc feat: add solutions to lc problem: No.2101 (#3147) Jun 22, 2024 CODE_OF_CONDUCT.md style: format code and documents Feb 15, 2022 Dockerfile chore: add Dockerfile (#3229) Jul 9, 2024 LICENSE docs: update LICENSE and SOLUTION_TREE Mar 21, 2019 README.md docs: add deep...
初始化字符串“122”,从索引2开始遍历,插入字符“1”。根据当前遍历的数字,选择插入的字符的个数。1插入完之后 换成插入2,2插入完之后换成插入1. 直到遍历到n 然后统计1出现的次数。 提交结果 482. 密钥格式化 有一个密钥字符串 S ,只包含字母,数字以及 ‘-’(破折号)。其中, N 个‘-’ 将字符串分成了...
A collection of Python codes for Leetcode Problem of the Day leetcode leetcode-solutions leetcode-practice leetcode-python leetcode-python3 leetcode-solution leetcode-programming-challenges leetcode-solutions-python problem-of-the-day problem-of-the-day-solutions leetcode-potd Updated Dec 23, ...
【题目】Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the “Pacific ocean” touches the left and top edges of the matrix and the “Atlantic ocean” touches the right and bottom edges. Water can only flow in four directions ...
Java classSolution{ publicintpartitionDisjoint(int[]nums){ intn=nums.length; int[]minn=newint[n+10]; minn[n-1]=nums[n-1]; for(inti=n-2;ii--) minn[i]=Math.min(minn[i+1],nums[i]); for(inti=0,maxx=0;in-1;i++){ maxx=Math.max(maxx,nums[i]); if(maxx=minn[i+1]) re...
classSolution{ public: TreeNode*sortedArrayToBST(vectorintnums){ returnhelper(nums,0,(int)nums.size()-1); TreeNode*helper(vectorintnums,intleft,intright){ if(leftright)returnNULL; intmid=left+(right-left)/2; TreeNode*cur=newTreeNode(nums[mid]); cur-left=helper(nums,left,mid-1); cur...