摘要: 45.跳跃游戏2 public int jump(int[] nums) { if(nums == null || nums.length < 1) { return 0; } int step = 0; int cur = 0; int next = nums[0]; for(int i = 1; 阅读全文
posted @ 2022-01-10 15:59 现在开始努力 阅读(28) 评论(0) 推荐(0)
摘要: 38.外观数列 public String countAndSay(int n) { if(n < 1) { return ""; } if(n == 1) { return "1"; } char[] pre = countAndSay(n - 1).toCharArray(); int time 阅读全文
posted @ 2022-01-05 14:55 现在开始努力 阅读(24) 评论(0) 推荐(0)
摘要: 33.搜索旋转排序数组 public int search(int[] nums, int target) { if(nums == null || nums.length == 0) { return -1; } int left = 0; int mid = 0; int right = num 阅读全文
posted @ 2022-01-04 16:35 现在开始努力 阅读(30) 评论(0) 推荐(0)
摘要: 22.括号生成 public List<String> generateParenthesis(int n) { char path[] = new char[n * 2]; List<String> res = new ArrayList<>(); if(n == 0) { return res; 阅读全文
posted @ 2021-12-29 15:42 现在开始努力 阅读(22) 评论(0) 推荐(0)
摘要: 14.最长公共前缀 public String longestCommonPrefix(String[] strs) { String first = strs[0]; char f[] = first.toCharArray(); int res = first.length(); for(int 阅读全文
posted @ 2021-12-28 15:45 现在开始努力 阅读(36) 评论(0) 推荐(0)
摘要: 7.整数反转 public int reverse(int x) { boolean isFu = x < 0 ? true : false; x = isFu ? x : -x; int res = 0; int M = Integer.MIN_VALUE / 10; int N = Int 阅读全文
posted @ 2021-12-22 14:53 现在开始努力 阅读(22) 评论(0) 推荐(0)
摘要: 1.两数之和 public int[] twoSum(int[] nums, int target) { HashMap<Integer,Integer> hm = new HashMap<>(); int res[] = new int[2]; for(int i = 0;i < nums.len 阅读全文
posted @ 2021-12-21 16:32 现在开始努力 阅读(43) 评论(0) 推荐(0)
摘要: 1.机器人问题,一共有1-N N个位置,机器人可以在1-N上任意移动,初始位置为start,目标位置为aim,可以移动K次,求有几种移动方式 (1)递归实现 public int ways3(int N,int start,int aim,int K) { return process3(start 阅读全文
posted @ 2021-12-02 18:02 现在开始努力 阅读(55) 评论(0) 推荐(0)
摘要: 滑动窗口最大值 public int[] maxSlidingWindow(int[] nums, int k) { if(nums == null || k < 1 || nums.length < k) { return new int[0]; } LinkedList<Integer> lis 阅读全文
posted @ 2021-11-23 16:40 现在开始努力 阅读(35) 评论(0) 推荐(0)
摘要: 最长公共子序列 class Solution { public int longestCommonSubsequence(String text1, String text2) { char s1[] = text1.toCharArray(); char s2[] = text2.toCharAr 阅读全文
posted @ 2021-11-17 15:05 现在开始努力 阅读(26) 评论(0) 推荐(0)