上一页 1 ··· 7 8 9 10 11 12 13 14 下一页
摘要: 力扣题目链接 class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode root = new ListNode(0); ListNode cursor = root; //保存进位值 int 阅读全文
posted @ 2022-02-04 19:15 蹇爱黄 阅读(26) 评论(0) 推荐(0)
摘要: 力扣题目链接 class Solution { public int numSubarrayProductLessThanK(int[] nums, int k) { if(k < 2) return 0; int i = 0,j = 0; int ans = 0; int x = 1; while 阅读全文
posted @ 2022-02-04 18:46 蹇爱黄 阅读(28) 评论(0) 推荐(0)
摘要: 力扣题目 解题思路: 双指针(有点滑动窗口的思想) 1.初始话最短数组的长度 min = Integer.MAX_VALUE 2.初始化一个数组的和 sum = 0; 3.定义变量(窗口的前后指针)i=0 j=0 j为快指针 4.开始遍历,当sum的值大于等于target时更新min 5.缩小窗口范 阅读全文
posted @ 2022-02-04 18:03 蹇爱黄 阅读(46) 评论(0) 推荐(0)
摘要: 力扣题目链接 6ms有点长也不知道咋优化 class Solution { public int threeSumClosest(int[] nums, int target) { int n = nums.length; //先排个序 Arrays.sort(nums); //记录第一个值 int 阅读全文
posted @ 2022-02-04 01:11 蹇爱黄 阅读(28) 评论(0) 推荐(0)
摘要: 力扣题目链接 第一种1ms class Solution { public String longestCommonPrefix(String[] strs) { //求出字符数组长度,方便后边遍历 int n = strs.length; if(n==0) return ""; //初始化返回值 阅读全文
posted @ 2022-02-04 00:09 蹇爱黄 阅读(37) 评论(0) 推荐(0)
摘要: 力扣题目链接 class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> res = new ArrayList<>(); int n = nums.length; //剪枝,当数组小于 阅读全文
posted @ 2022-02-03 22:19 蹇爱黄 阅读(36) 评论(0) 推荐(0)
摘要: 力扣题目链接 跟两数之和好像啊 于是写了一个HashMap class Solution { public int[] twoSum(int[] numbers, int target) { int[] a = new int[2]; Map<Integer,Integer> map = new H 阅读全文
posted @ 2022-02-03 21:11 蹇爱黄 阅读(30) 评论(0) 推荐(0)
摘要: 力扣题目链接 感觉自己是真的菜。。。每次都看大佬题解 public class Solution { public int maxProduct(String[] words) { //字符数组的长度 int len = words.length; //定义一个长度为字符数组长度的新数组 int[] 阅读全文
posted @ 2022-02-03 20:47 蹇爱黄 阅读(38) 评论(0) 推荐(0)
摘要: 力扣题目链接 不知道别的方法怎么样,只能想出HashMap class Solution { public int singleNumber(int[] nums) { Map<Integer,Integer> map = new HashMap<Integer,Integer>(); for(in 阅读全文
posted @ 2022-02-03 18:11 蹇爱黄 阅读(29) 评论(0) 推荐(0)
摘要: 力扣题目链接 位运算 class Solution { public int[] countBits(int n) { int[] nums = new int[n+1]; for(int i=0;i<=n;++i){ for(int j=0;j<32;++j){ nums[i] += (i>>j) 阅读全文
posted @ 2022-02-03 16:52 蹇爱黄 阅读(23) 评论(0) 推荐(0)
上一页 1 ··· 7 8 9 10 11 12 13 14 下一页