LeetCode解题报告--4Sum

Vue3实战:从零构建ElementPlus后台管理系统全流程 本文详细介绍了从零开始使用Vue3和ElementPlus构建后台管理系统的全流程。内容涵盖环境准备、项目初始化、Vite配置、SCSS样式体系搭建、ElementPlus组件库引入与配置,以及封装可复用的SvgIcon组件进行图标管理,旨在帮助开发者快速搭建现代化、可维护的中后台应用。 阅读详情

题目: 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.

Note:
Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a ≤ b ≤ c ≤ d)
The solution set must not contain duplicate quadruplets.
For example, given array S = {1 0 -1 0 -2 2}, and target = 0.

A solution set is:
(-1,  0, 0, 1)
(-2, -1, 1, 2)
(-2,  0, 0, 2)

原题链接地址:https://leetcode.com/problems/4sum/

分析:该问题与leetcode 3sum问题解题思路一样,都是由2Sum问题的基础拓展开来。在3sum基础加for循环,时间复杂度为0(N^2).具体可参见3sum,这里直接贴出accepted代码。下一篇关于2Sum,3Sum(closest),4Sum的问题总结,延伸至KSum问题!

java代码:(accepted)

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class FourSum {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] arrays = new int[]{7, -1, 14, -12, -8, 7, 2, -15, 8, 8, -8, -14, -4,
                -5, 7, 9, 11, -4, -15, -6, 1, -14, 4, 3, 10, -5, 2, 1, 6, 11,
                2, -2, -5, -7, -6, 2, -15, 11, -6, 8, -4, 2, 1, -1, 4, -6, -15,
                1, 5, -15, 10, 14, 9, -8, -6, 4, -6, 11, 12, -15, 7, -1, -9, 9,
                -1, 0, -4, -1, -12, -2, 14, -9, 7, 0, -3, -4, 1, -2, 12, 14,
                -10, 0, 5, 14, -1, 14, 3, 8, 10, -8, 8, -5, -2, 6, -11, 12, 13,
                -7, -12, 8, 6, -13, 14, -2, -5, -11, 1, 3, -6 };
        List<List<Integer>> result = new ArrayList<List<Integer>>();
        result = fourSum(arrays,0);
        for(int i = 0;i < result.size();i ++)
            System.out.println(result.get(i));
    }

    public static List<List<Integer>> fourSum(int[] nums, int target) {

        List<List<Integer>> result = new ArrayList<List<Integer>>();
        HashSet<List<Integer>> elementSet = new HashSet<List<Integer>>();
        Arrays.sort(nums);

        for(int i = 0;i < nums.length - 3;i ++){
            for(int j = i + 1;j < nums.length - 2;j ++){
                int left = j + 1;
                int right = nums.length - 1;
                while(left < right){
                    int sum = nums[i] + nums[j] + nums[left] + nums[right];
                    if(sum == target){
                        List<Integer> taplet = new ArrayList<Integer>();
                        taplet.add(nums[i]);
                        taplet.add(nums[j]);
                        taplet.add(nums[left]);
                        taplet.add(nums[right]);
                        if(!elementSet.contains(taplet)){
                            result.add(taplet);
                            elementSet.add(taplet);
                        }
                        left ++;
                        right --;
                    }else if(sum < target){
                        left ++;
                    }else{
                        right --;
                    }
                }
            }
        }
        return result;
    }

}

测试结果:

[-15, -13, 14, 14]
[-15, -12, 13, 14]
[-15, -11, 12, 14]
[-15, -10, 11, 14]
[-15, -10, 12, 13]
[-15, -9, 10, 14]
[-15, -9, 11, 13]
[-15, -9, 12, 12]
[-15, -8, 9, 14]
[-15, -8, 10, 13]
[-15, -8, 11, 12]
[-15, -7, 8, 14]
[-15, -7, 9, 13]
[-15, -7, 10, 12]
[-15, -7, 11, 11]
[-15, -6, 7, 14]
[-15, -6, 8, 13]
[-15, -6, 9, 12]
[-15, -6, 10, 11]
[-15, -5, 6, 14]
[-15, -5, 7, 13]
[-15, -5, 8, 12]
[-15, -5, 9, 11]
[-15, -5, 10, 10]
[-15, -4, 5, 14]
[-15, -4, 6, 13]
[-15, -4, 7, 12]
[-15, -4, 8, 11]
[-15, -4, 9, 10]
[-15, -3, 4, 14]
[-15, -3, 5, 13]
[-15, -3, 6, 12]
[-15, -3, 7, 11]
[-15, -3, 8, 10]
[-15, -3, 9, 9]
[-15, -2, 3, 14]
[-15, -2, 4, 13]
[-15, -2, 5, 12]
[-15, -2, 6, 11]
[-15, -2, 7, 10]
[-15, -2, 8, 9]
[-15, -1, 2, 14]
[-15, -1, 3, 13]
[-15, -1, 4, 12]
[-15, -1, 5, 11]
[-15, -1, 6, 10]
[-15, -1, 7, 9]
[-15, -1, 8, 8]
[-15, 0, 1, 14]
[-15, 0, 2, 13]
[-15, 0, 3, 12]
[-15, 0, 4, 11]
[-15, 0, 5, 10]
[-15, 0, 6, 9]
[-15, 0, 7, 8]
[-15, 1, 1, 13]
[-15, 1, 2, 12]
[-15, 1, 3, 11]
[-15, 1, 4, 10]
[-15, 1, 5, 9]
[-15, 1, 6, 8]
[-15, 1, 7, 7]
[-15, 2, 2, 11]
[-15, 2, 3, 10]
[-15, 2, 4, 9]
[-15, 2, 5, 8]
[-15, 2, 6, 7]
[-15, 3, 3, 9]
[-15, 3, 4, 8]
[-15, 3, 5, 7]
[-15, 3, 6, 6]
[-15, 4, 4, 7]
[-15, 4, 5, 6]
[-14, -14, 14, 14]
[-14, -13, 13, 14]
[-14, -12, 12, 14]
[-14, -11, 11, 14]
[-14, -11, 12, 13]
[-14, -10, 10, 14]
[-14, -10, 11, 13]
[-14, -10, 12, 12]
[-14, -9, 9, 14]
[-14, -9, 10, 13]
[-14, -9, 11, 12]
[-14, -8, 8, 14]
[-14, -8, 9, 13]
[-14, -8, 10, 12]
[-14, -8, 11, 11]
[-14, -7, 7, 14]
[-14, -7, 8, 13]
[-14, -7, 9, 12]
[-14, -7, 10, 11]
[-14, -6, 6, 14]
[-14, -6, 7, 13]
[-14, -6, 8, 12]
[-14, -6, 9, 11]
[-14, -6, 10, 10]
[-14, -5, 5, 14]
[-14, -5, 6, 13]
[-14, -5, 7, 12]
[-14, -5, 8, 11]
[-14, -5, 9, 10]
[-14, -4, 4, 14]
[-14, -4, 5, 13]
[-14, -4, 6, 12]
[-14, -4, 7, 11]
[-14, -4, 8, 10]
[-14, -4, 9, 9]
[-14, -3, 3, 14]
[-14, -3, 4, 13]
[-14, -3, 5, 12]
[-14, -3, 6, 11]
[-14, -3, 7, 10]
[-14, -3, 8, 9]
[-14, -2, 2, 14]
[-14, -2, 3, 13]
[-14, -2, 4, 12]
[-14, -2, 5, 11]
[-14, -2, 6, 10]
[-14, -2, 7, 9]
[-14, -2, 8, 8]
[-14, -1, 1, 14]
[-14, -1, 2, 13]
[-14, -1, 3, 12]
[-14, -1, 4, 11]
[-14, -1, 5, 10]
[-14, -1, 6, 9]
[-14, -1, 7, 8]
[-14, 0, 0, 14]
[-14, 0, 1, 13]
[-14, 0, 2, 12]
[-14, 0, 3, 11]
[-14, 0, 4, 10]
[-14, 0, 5, 9]
[-14, 0, 6, 8]
[-14, 0, 7, 7]
[-14, 1, 1, 12]
[-14, 1, 2, 11]
[-14, 1, 3, 10]
[-14, 1, 4, 9]
[-14, 1, 5, 8]
[-14, 1, 6, 7]
[-14, 2, 2, 10]
[-14, 2, 3, 9]
[-14, 2, 4, 8]
[-14, 2, 5, 7]
[-14, 2, 6, 6]
[-14, 3, 3, 8]
[-14, 3, 4, 7]
[-14, 3, 5, 6]
[-14, 4, 4, 6]
[-14, 4, 5, 5]
[-13, -12, 11, 14]
[-13, -12, 12, 13]
[-13, -11, 10, 14]
[-13, -11, 11, 13]
[-13, -11, 12, 12]
[-13, -10, 9, 14]
[-13, -10, 10, 13]
[-13, -10, 11, 12]
[-13, -9, 8, 14]
[-13, -9, 9, 13]
[-13, -9, 10, 12]
[-13, -9, 11, 11]
[-13, -8, 7, 14]
[-13, -8, 8, 13]
[-13, -8, 9, 12]
[-13, -8, 10, 11]
[-13, -7, 6, 14]
[-13, -7, 7, 13]
[-13, -7, 8, 12]
[-13, -7, 9, 11]
[-13, -7, 10, 10]
[-13, -6, 5, 14]
[-13, -6, 6, 13]
[-13, -6, 7, 12]
[-13, -6, 8, 11]
[-13, -6, 9, 10]
[-13, -5, 4, 14]
[-13, -5, 5, 13]
[-13, -5, 6, 12]
[-13, -5, 7, 11]
[-13, -5, 8, 10]
[-13, -5, 9, 9]
[-13, -4, 3, 14]
[-13, -4, 4, 13]
[-13, -4, 5, 12]
[-13, -4, 6, 11]
[-13, -4, 7, 10]
[-13, -4, 8, 9]
[-13, -3, 2, 14]
[-13, -3, 3, 13]
[-13, -3, 4, 12]
[-13, -3, 5, 11]
[-13, -3, 6, 10]
[-13, -3, 7, 9]
[-13, -3, 8, 8]
[-13, -2, 1, 14]
[-13, -2, 2, 13]
[-13, -2, 3, 12]
[-13, -2, 4, 11]
[-13, -2, 5, 10]
[-13, -2, 6, 9]
[-13, -2, 7, 8]
[-13, -1, 0, 14]
[-13, -1, 1, 13]
[-13, -1, 2, 12]
[-13, -1, 3, 11]
[-13, -1, 4, 10]
[-13, -1, 5, 9]
[-13, -1, 6, 8]
[-13, -1, 7, 7]
[-13, 0, 0, 13]
[-13, 0, 1, 12]
[-13, 0, 2, 11]
[-13, 0, 3, 10]
[-13, 0, 4, 9]
[-13, 0, 5, 8]
[-13, 0, 6, 7]
[-13, 1, 1, 11]
[-13, 1, 2, 10]
[-13, 1, 3, 9]
[-13, 1, 4, 8]
[-13, 1, 5, 7]
[-13, 1, 6, 6]
[-13, 2, 2, 9]
[-13, 2, 3, 8]
[-13, 2, 4, 7]
[-13, 2, 5, 6]
[-13, 3, 3, 7]
[-13, 3, 4, 6]
[-13, 3, 5, 5]
[-13, 4, 4, 5]
[-12, -12, 10, 14]
[-12, -12, 11, 13]
[-12, -12, 12, 12]
[-12, -11, 9, 14]
[-12, -11, 10, 13]
[-12, -11, 11, 12]
[-12, -10, 8, 14]
[-12, -10, 9, 13]
[-12, -10, 10, 12]
[-12, -10, 11, 11]
[-12, -9, 7, 14]
[-12, -9, 8, 13]
[-12, -9, 9, 12]
[-12, -9, 10, 11]
[-12, -8, 6, 14]
[-12, -8, 7, 13]
[-12, -8, 8, 12]
[-12, -8, 9, 11]
[-12, -8, 10, 10]
[-12, -7, 5, 14]
[-12, -7, 6, 13]
[-12, -7, 7, 12]
[-12, -7, 8, 11]
[-12, -7, 9, 10]
[-12, -6, 4, 14]
[-12, -6, 5, 13]
[-12, -6, 6, 12]
[-12, -6, 7, 11]
[-12, -6, 8, 10]
[-12, -6, 9, 9]
[-12, -5, 3, 14]
[-12, -5, 4, 13]
[-12, -5, 5, 12]
[-12, -5, 6, 11]
[-12, -5, 7, 10]
[-12, -5, 8, 9]
[-12, -4, 2, 14]
[-12, -4, 3, 13]
[-12, -4, 4, 12]
[-12, -4, 5, 11]
[-12, -4, 6, 10]
[-12, -4, 7, 9]
[-12, -4, 8, 8]
[-12, -3, 1, 14]
[-12, -3, 2, 13]
[-12, -3, 3, 12]
[-12, -3, 4, 11]
[-12, -3, 5, 10]
[-12, -3, 6, 9]
[-12, -3, 7, 8]
[-12, -2, 0, 14]
[-12, -2, 1, 13]
[-12, -2, 2, 12]
[-12, -2, 3, 11]
[-12, -2, 4, 10]
[-12, -2, 5, 9]
[-12, -2, 6, 8]
[-12, -2, 7, 7]
[-12, -1, -1, 14]
[-12, -1, 0, 13]
[-12, -1, 1, 12]
[-12, -1, 2, 11]
[-12, -1, 3, 10]
[-12, -1, 4, 9]
[-12, -1, 5, 8]
[-12, -1, 6, 7]
[-12, 0, 0, 12]
[-12, 0, 1, 11]
[-12, 0, 2, 10]
[-12, 0, 3, 9]
[-12, 0, 4, 8]
[-12, 0, 5, 7]
[-12, 0, 6, 6]
[-12, 1, 1, 10]
[-12, 1, 2, 9]
[-12, 1, 3, 8]
[-12, 1, 4, 7]
[-12, 1, 5, 6]
[-12, 2, 2, 8]
[-12, 2, 3, 7]
[-12, 2, 4, 6]
[-12, 2, 5, 5]
[-12, 3, 3, 6]
[-12, 3, 4, 5]
[-12, 4, 4, 4]
[-11, -11, 8, 14]
[-11, -11, 9, 13]
[-11, -11, 10, 12]
[-11, -11, 11, 11]
[-11, -10, 7, 14]
[-11, -10, 8, 13]
[-11, -10, 9, 12]
[-11, -10, 10, 11]
[-11, -9, 6, 14]
[-11, -9, 7, 13]
[-11, -9, 8, 12]
[-11, -9, 9, 11]
[-11, -9, 10, 10]
[-11, -8, 5, 14]
[-11, -8, 6, 13]
[-11, -8, 7, 12]
[-11, -8, 8, 11]
[-11, -8, 9, 10]
[-11, -7, 4, 14]
[-11, -7, 5, 13]
[-11, -7, 6, 12]
[-11, -7, 7, 11]
[-11, -7, 8, 10]
[-11, -7, 9, 9]
[-11, -6, 3, 14]
[-11, -6, 4, 13]
[-11, -6, 5, 12]
[-11, -6, 6, 11]
[-11, -6, 7, 10]
[-11, -6, 8, 9]
[-11, -5, 2, 14]
[-11, -5, 3, 13]
[-11, -5, 4, 12]
[-11, -5, 5, 11]
[-11, -5, 6, 10]
[-11, -5, 7, 9]
[-11, -5, 8, 8]
[-11, -4, 1, 14]
[-11, -4, 2, 13]
[-11, -4, 3, 12]
[-11, -4, 4, 11]
[-11, -4, 5, 10]
[-11, -4, 6, 9]
[-11, -4, 7, 8]
[-11, -3, 0, 14]
[-11, -3, 1, 13]
[-11, -3, 2, 12]
[-11, -3, 3, 11]
[-11, -3, 4, 10]
[-11, -3, 5, 9]
[-11, -3, 6, 8]
[-11, -3, 7, 7]
[-11, -2, -1, 14]
[-11, -2, 0, 13]
[-11, -2, 1, 12]
[-11, -2, 2, 11]
[-11, -2, 3, 10]
[-11, -2, 4, 9]
[-11, -2, 5, 8]
[-11, -2, 6, 7]
[-11, -1, -1, 13]
[-11, -1, 0, 12]
[-11, -1, 1, 11]
[-11, -1, 2, 10]
[-11, -1, 3, 9]
[-11, -1, 4, 8]
[-11, -1, 5, 7]
[-11, -1, 6, 6]
[-11, 0, 0, 11]
[-11, 0, 1, 10]
[-11, 0, 2, 9]
[-11, 0, 3, 8]
[-11, 0, 4, 7]
[-11, 0, 5, 6]
[-11, 1, 1, 9]
[-11, 1, 2, 8]
[-11, 1, 3, 7]
[-11, 1, 4, 6]
[-11, 1, 5, 5]
[-11, 2, 2, 7]
[-11, 2, 3, 6]
[-11, 2, 4, 5]
[-11, 3, 3, 5]
[-11, 3, 4, 4]
[-10, -9, 5, 14]
[-10, -9, 6, 13]
[-10, -9, 7, 12]
[-10, -9, 8, 11]
[-10, -9, 9, 10]
[-10, -8, 4, 14]
[-10, -8, 5, 13]
[-10, -8, 6, 12]
[-10, -8, 7, 11]
[-10, -8, 8, 10]
[-10, -8, 9, 9]
[-10, -7, 3, 14]
[-10, -7, 4, 13]
[-10, -7, 5, 12]
[-10, -7, 6, 11]
[-10, -7, 7, 10]
[-10, -7, 8, 9]
[-10, -6, 2, 14]
[-10, -6, 3, 13]
[-10, -6, 4, 12]
[-10, -6, 5, 11]
[-10, -6, 6, 10]
[-10, -6, 7, 9]
[-10, -6, 8, 8]
[-10, -5, 1, 14]
[-10, -5, 2, 13]
[-10, -5, 3, 12]
[-10, -5, 4, 11]
[-10, -5, 5, 10]
[-10, -5, 6, 9]
[-10, -5, 7, 8]
[-10, -4, 0, 14]
[-10, -4, 1, 13]
[-10, -4, 2, 12]
[-10, -4, 3, 11]
[-10, -4, 4, 10]
[-10, -4, 5, 9]
[-10, -4, 6, 8]
[-10, -4, 7, 7]
[-10, -3, -1, 14]
[-10, -3, 0, 13]
[-10, -3, 1, 12]
[-10, -3, 2, 11]
[-10, -3, 3, 10]
[-10, -3, 4, 9]
[-10, -3, 5, 8]
[-10, -3, 6, 7]
[-10, -2, -2, 14]
[-10, -2, -1, 13]
[-10, -2, 0, 12]
[-10, -2, 1, 11]
[-10, -2, 2, 10]
[-10, -2, 3, 9]
[-10, -2, 4, 8]
[-10, -2, 5, 7]
[-10, -2, 6, 6]
[-10, -1, -1, 12]
[-10, -1, 0, 11]
[-10, -1, 1, 10]
[-10, -1, 2, 9]
[-10, -1, 3, 8]
[-10, -1, 4, 7]
[-10, -1, 5, 6]
[-10, 0, 0, 10]
[-10, 0, 1, 9]
[-10, 0, 2, 8]
[-10, 0, 3, 7]
[-10, 0, 4, 6]
[-10, 0, 5, 5]
[-10, 1, 1, 8]
[-10, 1, 2, 7]
[-10, 1, 3, 6]
[-10, 1, 4, 5]
[-10, 2, 2, 6]
[-10, 2, 3, 5]
[-10, 2, 4, 4]
[-10, 3, 3, 4]
[-9, -9, 4, 14]
[-9, -9, 5, 13]
[-9, -9, 6, 12]
[-9, -9, 7, 11]
[-9, -9, 8, 10]
[-9, -9, 9, 9]
[-9, -8, 3, 14]
[-9, -8, 4, 13]
[-9, -8, 5, 12]
[-9, -8, 6, 11]
[-9, -8, 7, 10]
[-9, -8, 8, 9]
[-9, -7, 2, 14]
[-9, -7, 3, 13]
[-9, -7, 4, 12]
[-9, -7, 5, 11]
[-9, -7, 6, 10]
[-9, -7, 7, 9]
[-9, -7, 8, 8]
[-9, -6, 1, 14]
[-9, -6, 2, 13]
[-9, -6, 3, 12]
[-9, -6, 4, 11]
[-9, -6, 5, 10]
[-9, -6, 6, 9]
[-9, -6, 7, 8]
[-9, -5, 0, 14]
[-9, -5, 1, 13]
[-9, -5, 2, 12]
[-9, -5, 3, 11]
[-9, -5, 4, 10]
[-9, -5, 5, 9]
[-9, -5, 6, 8]
[-9, -5, 7, 7]
[-9, -4, -1, 14]
[-9, -4, 0, 13]
[-9, -4, 1, 12]
[-9, -4, 2, 11]
[-9, -4, 3, 10]
[-9, -4, 4, 9]
[-9, -4, 5, 8]
[-9, -4, 6, 7]
[-9, -3, -2, 14]
[-9, -3, -1, 13]
[-9, -3, 0, 12]
[-9, -3, 1, 11]
[-9, -3, 2, 10]
[-9, -3, 3, 9]
[-9, -3, 4, 8]
[-9, -3, 5, 7]
[-9, -3, 6, 6]
[-9, -2, -2, 13]
[-9, -2, -1, 12]
[-9, -2, 0, 11]
[-9, -2, 1, 10]
[-9, -2, 2, 9]
[-9, -2, 3, 8]
[-9, -2, 4, 7]
[-9, -2, 5, 6]
[-9, -1, -1, 11]
[-9, -1, 0, 10]
[-9, -1, 1, 9]
[-9, -1, 2, 8]
[-9, -1, 3, 7]
[-9, -1, 4, 6]
[-9, -1, 5, 5]
[-9, 0, 0, 9]
[-9, 0, 1, 8]
[-9, 0, 2, 7]
[-9, 0, 3, 6]
[-9, 0, 4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4]
[-8, 1, 1, 6]
[-8, 1, 2, 5]
[-8, 1, 3, 4]
[-8, 2, 2, 4]
[-8, 2, 3, 3]
[-7, -7, 0, 14]
[-7, -7, 1, 13]
[-7, -7, 2, 12]
[-7, -7, 3, 11]
[-7, -7, 4, 10]
[-7, -7, 5, 9]
[-7, -7, 6, 8]
[-7, -7, 7, 7]
[-7, -6, -1, 14]
[-7, -6, 0, 13]
[-7, -6, 1, 12]
[-7, -6, 2, 11]
[-7, -6, 3, 10]
[-7, -6, 4, 9]
[-7, -6, 5, 8]
[-7, -6, 6, 7]
[-7, -5, -2, 14]
[-7, -5, -1, 13]
[-7, -5, 0, 12]
[-7, -5, 1, 11]
[-7, -5, 2, 10]
[-7, -5, 3, 9]
[-7, -5, 4, 8]
[-7, -5, 5, 7]
[-7, -5, 6, 6]
[-7, -4, -3, 14]
[-7, -4, -2, 13]
[-7, -4, -1, 12]
[-7, -4, 0, 11]
[-7, -4, 1, 10]
[-7, -4, 2, 9]
[-7, -4, 3, 8]
[-7, -4, 4, 7]
[-7, -4, 5, 6]
[-7, -3, -2, 12]
[-7, -3, -1, 11]
[-7, -3, 0, 10]
[-7, -3, 1, 9]
[-7, -3, 2, 8]
[-7, -3, 3, 7]
[-7, -3, 4, 6]
[-7, -3, 5, 5]
[-7, -2, -2, 11]
[-7, -2, -1, 10]
[-7, -2, 0, 9]
[-7, -2, 1, 8]
[-7, -2, 2, 7]
[-7, -2, 3, 6]
[-7, -2, 4, 5]
[-7, -1, -1, 9]
[-7, -1, 0, 8]
[-7, -1, 1, 7]
[-7, -1, 2, 6]
[-7, -1, 3, 5]
[-7, -1, 4, 4]
[-7, 0, 0, 7]
[-7, 0, 1, 6]
[-7, 0, 2, 5]
[-7, 0, 3, 4]
[-7, 1, 1, 5]
[-7, 1, 2, 4]
[-7, 1, 3, 3]
[-7, 2, 2, 3]
[-6, -6, -2, 14]
[-6, -6, -1, 13]
[-6, -6, 0, 12]
[-6, -6, 1, 11]
[-6, -6, 2, 10]
[-6, -6, 3, 9]
[-6, -6, 4, 8]
[-6, -6, 5, 7]
[-6, -6, 6, 6]
[-6, -5, -3, 14]
[-6, -5, -2, 13]
[-6, -5, -1, 12]
[-6, -5, 0, 11]
[-6, -5, 1, 10]
[-6, -5, 2, 9]
[-6, -5, 3, 8]
[-6, -5, 4, 7]
[-6, -5, 5, 6]
[-6, -4, -4, 14]
[-6, -4, -3, 13]
[-6, -4, -2, 12]
[-6, -4, -1, 11]
[-6, -4, 0, 10]
[-6, -4, 1, 9]
[-6, -4, 2, 8]
[-6, -4, 3, 7]
[-6, -4, 4, 6]
[-6, -4, 5, 5]
[-6, -3, -2, 11]
[-6, -3, -1, 10]
[-6, -3, 0, 9]
[-6, -3, 1, 8]
[-6, -3, 2, 7]
[-6, -3, 3, 6]
[-6, -3, 4, 5]
[-6, -2, -2, 10]
[-6, -2, -1, 9]
[-6, -2, 0, 8]
[-6, -2, 1, 7]
[-6, -2, 2, 6]
[-6, -2, 3, 5]
[-6, -2, 4, 4]
[-6, -1, -1, 8]
[-6, -1, 0, 7]
[-6, -1, 1, 6]
[-6, -1, 2, 5]
[-6, -1, 3, 4]
[-6, 0, 0, 6]
[-6, 0, 1, 5]
[-6, 0, 2, 4]
[-6, 0, 3, 3]
[-6, 1, 1, 4]
[-6, 1, 2, 3]
[-6, 2, 2, 2]
[-5, -5, -4, 14]
[-5, -5, -3, 13]
[-5, -5, -2, 12]
[-5, -5, -1, 11]
[-5, -5, 0, 10]
[-5, -5, 1, 9]
[-5, -5, 2, 8]
[-5, -5, 3, 7]
[-5, -5, 4, 6]
[-5, -5, 5, 5]
[-5, -4, -4, 13]
[-5, -4, -3, 12]
[-5, -4, -2, 11]
[-5, -4, -1, 10]
[-5, -4, 0, 9]
[-5, -4, 1, 8]
[-5, -4, 2, 7]
[-5, -4, 3, 6]
[-5, -4, 4, 5]
[-5, -3, -2, 10]
[-5, -3, -1, 9]
[-5, -3, 0, 8]
[-5, -3, 1, 7]
[-5, -3, 2, 6]
[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码放在个人github:https://github.com/gannyee/LeetCode/

立创·庐山派-K230-CanMV(嘉楠勘智)开发板通过ATK-ESP8266实现图像识别数据无线传输至原子云 本文详细介绍了如何使用立创·庐山派-K230-CanMV开发板,通过ATK-ESP8266 WIFI模块实现图像识别数据的无线传输至原子云平台。内容包括硬件连接、软件环境搭建、AT指令控制、原子云连接及数据上传的全过程,并提供了实用的调试技巧和常见问题解决方案,为物联网应用开发提供了完整实践指南。 阅读详情

相关推荐

基于Xilinx_IBERT的光纤接口眼图测试

基于Xilinx_IBERT的光纤接口眼图测试

Coca_Tian的博客 1万+

【解题报告】LeetCode

一、1984. 学生分数的最小差值 题目描述 给你一个 下标从 0 开始 的整数数组 nums ,其中 nums[i] 表示第 i 名学生的分数。另给你一个整数 k 。 从数组中选出任意 k 名学生的分数,使这 k 个分数间 最高分 和 最低分 的 差值 达到 最小化 。 返回可能的 最小差值 代码示例 class Solution { public: int minimumDifference(vector<int>& nums, int k) { sort

JYSimilar的博客 457

SAP接口错误查询日志

随着数字经济的迅速发展,企业数字化转型不在只追求“业财一体化”,而是在业务端也想要进行更为精细化的管理,所以很多企业在SAP ERP的基础上,集成更多垂直领域更精细的外围系统,比如销售CRM系统,采购SRM系统,生产MES系统等等,琳琅满目的产品,那对SAP实施来说,系统集成过程中,接口的一些报错查询能力必不可少,今天我们就介绍一下,SAP和CRM系统集成中接口常见的报错。

weixin_43657667的博客 2090

Leetcode 652. 寻找重复的子树

Leetcode 652. 寻找重复的子树

weixin_44852067的博客 440

论文解读--Phase Noise in FMCW Radar Systems

相位噪声是现代雷达、通信、光谱和计量系统的基本性能参数之一。本文提出了一种适用于FMCW雷达系统的相位噪声理论。导出了一个新的设计方程,用于确定雷达系统中允许的源相位噪声电平的最大界。分析了在传输延迟小于参考振荡器相干时间时,相干混频引起的非线性相位噪声去相关函数;讨论了在传输延迟大于参考振荡器相干时间时,目标响应的频谱展宽。提出了收发链中各子系统的影响,并讨论了一种新的ADC相位噪声模型。介绍了相位噪声建模技术,然后将锁相环频率合成器与低噪声频率合成器进行比较,以演示减少相位噪声边带以改善检测和跟踪性能。

奔袭的算法工程师 3783

多周期路径及set_multicycle_path详解

默认情况下,每条路径都被定义为单周期,即源触发器在时钟的任一边沿启动(launch)的数据都应该由目的触发器在时钟的下一上升沿捕获(capture)。 有的设计需要在数据被捕获前提供一些额外的周期,这类路径被称为多周期路径。 一、set_multicycle_path命令 命令格式如下: set_multicycle_path .........

Jackiezhang1993的博客 4万+

【LeetCode】Largest Number 解题报告

【题目】【LeetCode】Largest Number 解题报告 Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The resu

shishilami的专栏 212

Js逆向抖音a_bogus --/* V 1.0.1.19-fix.01 */补环境

需要在addEventListener中补一个鼠标移动事件,不补这个环境,生成的值是假值,你拿去请求,响应200,但是没有数据,这个算是dy的最难发现的一个难点。dy这个,没有原形链检测,我只是习惯了这样补,对XMLHttpRequest进行重写,导出a_bogus.发现可以响应状态码200,而且可以获取数据,接着注释params中的a_bogus。在n.apply的下面插入上述代码,对a_bogus进行全局导出。如果没有,就多放几次断点,因为每个人的游览器不一样。必须触发至少一次鼠标事件,不触发不给过。

2302_76420666的博客 4217

leetcode 解题报告(37-40)

37. Sudoku Solver 题目描述: 填数独,36题的升级版。 解题思路: DFS求解,解题逻辑就是先找个一个空格的位置,然后在这个位置上填入一个有效的数字,意味着填入的数值满足数独的三个约束条件,但是并不见得就是最终的答案,所以还需要递归验证,在填入这个数字的基础上,找到下一个空格,继续填入一个有效数字,一直往下验证,直到不符合条件时,修改填入的数字,再重新验证,直到找到最终的答案。...

qq_43461168的博客 268

Python爬虫实战:爬取携程旅游平台数据,我拆解了动态反爬+Cookie续命(附完整可运行代码)

反爬类型表现形式应对思路sign参数返回403/空数据逆向JS还原加密逻辑Cookie时效登录后1小时Cookie失效定时刷新Cookie/保存登录态行为检测爬取过快触发验证码模拟真人延时/随机点击IP封禁单IP爬取超50条数据被封付费代理池/降低请求频率爬取携程旅游平台数据的核心,不是“简单的HTTP请求”,而是“理解平台的反爬逻辑并合规适配”——从sign参数破解到Cookie维护,再到行为模拟,每一步都是对HTTP协议、前端加密、用户行为的深度理解。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1734

【深度学习新浪潮】李飞飞团队VAGEN框架深度解析:让VLM智能体学会“三思而后行“

VAGEN框架的真正价值,不仅在于性能指标的突破,更在于重新定义了VLM智能体的发展方向——人工智能的进步不应只追求"做得对",更要实现"想得清"。李飞飞团队通过强制显式思考、动态表示适配和精细化奖励三大创新,让智能体第一次具备了可解释的世界建模能力。正如人类通过"观察-预测-行动"认识世界,VAGEN为AI注入的这种思考范式,或许正是通往通用人工智能的关键一步。对于开发者而言,开源的VAGEN框架不仅提供了强大的工具,更揭示了一个重要理念:让AI学会思考,比让它学会执行更重要。

专注:太空算力、AI infra、异构调度、大模型成本工程 286

Leetcode刷题652. 寻找重复的子树

著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。对于同一类的重复子树,你只需要返回其中任意。来源:力扣(LeetCode)给你一棵二叉树的根节点。

Bonbon_wen的博客 407

一文掌握 MongoDB 详细安装与配置(Windows / Linux / macOS 全平台)

本文详细介绍了MongoDB社区版7.0+在Windows、Linux和macOS三大操作系统上的完整安装、配置与安全加固流程。主要内容包括:各平台推荐安装方式(Windows使用MSI安装包、Linux通过官方仓库、macOS通过Homebrew)、基本配置参数说明、服务启动方法以及关键安全措施(如创建管理员用户和启用身份验证)。文章还提供了系统最低要求、下载地址、数据目录设置建议以及生产环境使用注意事项,适合开发、测试及生产环境部署参考。

数据知道的博客 6762

[leetcode] 454. 4Sum II 解题报告

题目链接:https://leetcode.com/problems/4sum-ii/ Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make

小榕流光的专栏 2146

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

[leetcode] 18. 4Sum 解题报告

题目链接:https://leetcode.com/problems/4sum/ Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which

小榕流光的专栏 664

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

leetcode解题报告18. 4Sum

leetcode解题报告18. 4Sum题目地址 难度是medium题目描述和3SUM问题类似,输入一个整数数组,和一个目标整数target。从数组中选择4个数,使得这四个数之和等于arget。现在要求找出所有满足要求的四元组,并且要求这些四元组之间不重复(其中四元组里的元素是没有顺序的,即(1,2,3,4)和(4,3,2,1)是同一个四元组)我的思路在会做3sum问题的基础上,4sum问题就很简单

sysu_xiaoming的博客 371

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

[LeetCode]4Sum, 解题报告

前言 明天就要回京了,还是挺紧张的,今天还是要坚持的做做题目,看看android,晚上收拾一下行李,不得不说,家里还是很舒服的,尤其是搬了新家之后,我还有自己的书房,开心 上传一张图片,纪念一下,哎,博客写的越来越随意了 题目 Given an array S of n integers, are there elements a, b, c, an

小一的专栏 3014

【LeetCode】4Sum 解题报告

【题目】 Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note:

跳出温水的青蛙 1883

[LeetCode] 4Sum 解题报告

[题目] Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: The solutio

hubin00sx的博客 314

Leetcode 454. 4Sum II 四数之和2 解题报告

1 解题思想首先,这是一道远古之前的题的进化版: Leetcode #18 4Sum 四数之和 解题小节+K-Sum思想 但是我不想说那个题了,因为我也记不住了。。这道题意思就是ABCD四个数组,长度相同,现在问题你说分别从这四个数组中各挑一个数相加其和为0,有几种方式?首先这道题肯定不能四层循环遍历。我的做法是: 将四数转变为两个部分,首先遍历AB的组合(任意两个都可以),存下他们组合后的和的

MebiuW的专栏 6817

【LeetCode】18. 4Sum Closest 解题报告(Python)

题目分析: 这道题目与3Sum类似,只是变成了4Sum,可以再3Sum外加一层循环解决,在网上看到了另一种解法,先两两相加存到字典里,再双循环让目标减去两个数看结果是否在字典里,时间复杂度由O(n3)变为O(n2),所以我提供两种解法。第一种方法使用了字典,用空间换取时间,消耗大概是160ms,第二种消耗大概是1000ms。 第一种:字典查询法 代码说明: 1、双循环生成字典 for i in r...

L141210113的专栏 243

LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结

前言: 这几天在做LeetCode 里面有2sum, 3sum(closest), 4sum等问题, 这类问题是典型的递归思路解题。该这类问题的关键在于,在进行求和求解前,要先排序Arrays.sort()可实现,而本文则着重探讨关于KSum问题。 leetcode求和问...

aoe41606的博客 164

Leetcode18 :4sum 解题报告

int cmp(const void*a,const void*b){ return *(int *)a-*(int *)b; } int** fourSum(int* nums, int numsSize, int target, int* returnSize) { if(numsSize&lt;4)return 0; qsort(nums,numsSize,sizeo...

李威的博客 236

[Leetcode] 454. 4Sum II 解题报告

题目: Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l]is zero. To make problem a bit easier, all A, B, C, D hav

魔豆(Magicbean)的博客 366

[LeetCode 解题报告]018.4 Sum

Description: Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d =target? Find all unique quadruplets in the array which gives t...

CVer 503
上一篇: LeetCode解题报告--Letter Combinations of a Phone Number
下一篇: LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结
YatKam
博客等级 码龄12年 58粉丝 49原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址