LeeCode初级算法数组部分十一道题

真的神了~无意中发现1500道的2021LeetCode算法刷题pdf笔记 昨晚逛GitHub,无意中看到一位大佬的算法刷题笔记,感觉发现了宝藏!有些小伙伴可能已经发现了,但咱这里还是忍不住安利一波,怕有些小伙伴没有看到。 关于算法刷题的困惑和疑问也经常听朋友们提及。这份笔记里面共包含作者刷力扣算法题后整理的上千道题,每道题均附有详细题解过程。有了这个笔记的总结,对校招和社招的算法刷题帮助之大不言而喻,果断收藏安利。 累计1500+道...拿来即刷!word很大,你忍一下,我就不一一截图了,诸君自行下载哈。 可以看到,每道题的原题,题目大意,解题思路,以及代码实现都非常 阅读详情

LeeCode初级算法数组部分十一道题


差不多一周时间就写了11道题,纯纯废物

1删除排序数组中的重复项

1.1自己写的

本年度写的第一道算法题有点傻,特喜欢像大一ACM那样开个一百万的数组,思路就是从第二个元素开始和前一个数判断,如果相同直接continue,不同就放入新数组中,定义一个整数记录新数组长度,最后把新数组再循环复制给原数组

package primary;

/**
 * @Description:删除排序数组中的重复项
 * @Author Mr.cui
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2022/5/11
 */
public class array_01 {
    public static int removeDuplicates(int[] nums) {
        int length= nums.length; //数组原本的长度

        int LastLength=0;
        int b[] = new int[1000000];
        b[0]=nums[0];
        for(int i=1;i<length;i++){
            if (nums[i]==nums[i-1]){
                continue;
            }
            else{
                LastLength++;
                b[LastLength]=nums[i];
                System.out.println();

            }
        }
        for (int i=0;i<LastLength+1;i++){
            nums[i]=b[i];
        }
        return LastLength+1;
    }

    public static void main(String[] args) {
        int[] a = {1,2,3,3,4,4,5,5,5};

        int k = removeDuplicates(a); // 调用
        System.out.println(a);
    }
	

}

1.2他人优化算法

优化算法思路是定义一个数字p讲每个不一样的数字放到数组的前面,再定义一个数字来标记第一个不一样的数字,从前向后遍历,最后返回

package primary.array;

/**
 * @Description:优化解
 * @Author Mr.Cui
 * @Date 2022/5/11
 */
public class array_01better {
    public int removeDuplicates(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        int p = 0; //p是为了标记每一个不一样的数字
        int q = 1; //q是为了标记和p所对应的数字不一样的第一个数字
//        0 1 1 2 2 2  3 3 3
        while(q < nums.length){
            if(nums[p] != nums[q]){
                if(q - p > 1){ //这里是因为如果等于一则不需要挪位置
                    nums[p + 1] = nums[q];
                }
                p++;
            }
            q++;
        }
        return p + 1;
    }
//
//    作者:max-LFszNScOfE
//    链接:https://leetcode.cn/problems/remove-duplicates-from-sorted-array/solution/shuang-zhi-zhen-shan-chu-zhong-fu-xiang-dai-you-hu/
//    来源:力扣(LeetCode)
//    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
}

2.买卖股票的最佳时机 II

思路是没啥思路,只要后面比前面大加起来就完事了

package primary.array;

/**
 * @Description;买卖股票的最佳时机 II
 * @Author Mr.Cui
 * @Date 2022/5/11
 */
public class array_02 {
    public static int maxProfit(int[] prices) {
        int profit=0;
        for(int i=1;i<prices.length;i++){
            if(prices[i-1]<prices[i]){
                profit+=prices[i]-prices[i-1];
            }
        }
        return profit;
    };

    public static void main(String[] args) {
        int[] a={7,1,5,3,6,4};
        int x=maxProfit(a);
        System.out.println(x);
    }
}
//出生即最优

3.旋转数组

3.1 自己写的

思路就是把移动之后的数组下标对数组长度求余得到他在新数组的位置

在这里插入代码片package primary.array;

/**
 * @Description:旋转数组
 * @Author Mr.Cui
 * @Date 2022/6/1
 */
public class array_03 {

    public static int[] rotate(int[] nums, int k) {
        int nums1[] = new int[nums.length];
        for(int i=0;i<nums.length;i++){
            nums1[i]=nums[(i-k%nums.length+nums.length)%nums.length];
            System.out.println(nums1[i]);
        }
        return nums1;
    }

    public static void main(String[] args) {
        int[] nums={1,2};
        rotate(nums,3);
    }
}

3.2优化算法

也没有优化啥,就是格式看着顺眼了点,他是把原数组按整个循环把值赋给新数组,我是创建一个新数组,然后找它在原数组中对应的位置

package primary.array;

/**
 * @Description:该题优化思路是在我的基础上逆向思维,将每个原数组的值赋值到新的数组上,并且减少了特殊情况的出现
 * @Author Mr.Cui
 * @Date 2022/6/1
 */
public class array_03better {

    class Solution {
        public void rotate(int[] nums, int k) {
            int n = nums.length;
            int[] newArr = new int[n];
            for (int i = 0; i < n; ++i) {
                newArr[(i + k) % n] = nums[i];
            }
            System.arraycopy(newArr, 0, nums, 0, n);
        }
    }

//    作者:LeetCode-Solution
//    链接:https://leetcode.cn/problems/rotate-array/solution/xuan-zhuan-shu-zu-by-leetcode-solution-nipk/
//    来源:力扣(LeetCode)
//    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
}

4.存在重复元素

思路是先将原数组用java.util.Arrays自带的排序函数将它排序,再循环length-1次判断相邻的两个数是否相等

package primary.array;

import java.util.Arrays;

/**
 * @Description:存在重复数组
 * @Author Mr.Cui
 * @Date 2022/6/1
 */
public class array_04 {
    public static boolean containsDuplicate(int[] nums) {
        Arrays.sort(nums);
        for (int i =0;i<nums.length-1;i++){
            if (nums[i]==nums[i+1]){
                return true;
            }
        }
        return false;
    }
}

5只出现一次数组

5.1.by myself

思路:先将数组排序,然后判断数组首位的特殊情况,最后判断中间的数,返回只出现一次的数

package primary.array;

import java.util.Arrays;

/**
 * @Description:只出现一次数组
 * @Author Mr.Cui
 * @Date 2022/6/2
 */
public class array_05 {
    public static int singleNumber(int[] nums) {
        int x=nums.length;
        Arrays.sort(nums);
        if (x==1){
            return nums[0];
        }
        if (nums[0]!=nums[1]){
            return nums[0];
        }
        else if (nums[x-2]!=nums[x-1]){
            return nums[x-1];
        }
        for(int i=1;i<x-1;i++){
            if(nums[i]!=nums[i-1]&&nums[i]!=nums[i+1]){
                return nums[i];
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        int[] nums={1,4,1,1,1,4,5};
        System.out.println(singleNumber(nums));
    }
}

5.2 other

这个方法属实惊艳到我这种算法小白了,利用异或的交换律巧妙的得出只出现一次的数字

package primary.array;

/**
 * @Description:
 * @Author Mr.Cui:运用异或的乘法交换律,因为异或相同的数会被抵消掉,达到最后的值为只出现一次的数的目的
 * @Date 2022/6/2
 */
public class array_05better {
    public int singleNumber(int[] nums) {
        int ans = nums[0];
        if (nums.length > 1) {
            for (int i = 1; i < nums.length; i++) {
                ans = ans ^ nums[i];
            }
        }
        return ans;
//
//    作者:yinyinnie
//    链接:https://leetcode.cn/problems/single-number/solution/xue-suan-fa-jie-guo-xiang-dui-yu-guo-cheng-bu-na-y/
//    来源:力扣(LeetCode)
//    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
    }
}

6.两个数组的交集

6.1myself

思路是
1.先将两个数组都排序,
2.因为两个数组的交集长度不能确定,所以我这里创建一个集合来存放两个数组重复的部分,
3.然后定义两个坐标分别表示第一个数组和第二个数组的下标,然后遍历,如果i指向的值小于j指向的值,,说明i指向的值小了,i往后移一步;如果i指向的值大于j指向的值,说明j指向的值小了,j往后移一步,如果i和j指向的值相同,说明这两个值是重复的,把他加入到集合list中,然后i和j同时都往后移一步,
4.因为集合只能存放引用数据类型不能存放基本数据类型所以需要通过stream()方法拿到流对象,mapToInt拿到Int流对象,就可以toArray返回int数组了

package primary.array;

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

/**
 * @Description:两个数组的交集 II
 * @Author Mr.Cui
 * @Date 2022/6/2
 */
public class array_06 {
    public static int[] intersect(int[] nums1, int[] nums2) {
        List<Integer> list=new ArrayList<>();
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int i = 0;
        int j = 0;
        while (i < nums1.length && j < nums2.length) {
            if (nums1[i] < nums2[j]) {
                // 如果i指向的值小于j指向的值,,说明i指向
                // 的值小了,i往后移一步
                i++;
            } else if (nums1[i] > nums2[j]) {
                // 如果i指向的值大于j指向的值,说明j指向的值
                // 小了,j往后移一步
                j++;
            } else {
                // 如果i和j指向的值相同,说明这两个值是重复的,
                // 把他加入到集合list中,然后i和j同时都往后移一步
                list.add(nums1[i]);
                i++;
                j++;
            }
        }

//        int index = 0;
//        int[] res = new int[list.size()];
//        for (int k = 0; k < list.size(); k++) {
//            res[index++] = list.get(k);
//        }
//        //通过stream()方法拿到流对象,mapToInt拿到Int流对象,就可以toArray返回int数组了
        int[] res = list.stream().mapToInt(Integer::intValue).toArray();
        return res;

    }

    public static void main(String[] args) {
        int[] nums1 = {1,2}; //458799
        int[] nums2 = {1,1};   //44899
        int[] nums3=intersect(nums1,nums2);
        for (int i=0;i<nums3.length;i++){
            System.out.println(nums3[i]);
        }

    }
}

6.2 other

优化算法是创建了一个两个数组中较小长度的数组,并且理论上copyOfRange()方法比通过stream()方法拿到流对象,mapToInt拿到Int流对象toArray返回int数组快

package primary.array;

import java.util.Arrays;

/**
 * @Description:这里的优化有创建较小长度数组以及最后直接返回被复制的数组,我之前的想法是先创建一个数组接被复制的数组,浪费了空间
 * 并且理论上copyOfRange()方法比通过stream()方法拿到流对象,mapToInt拿到Int流对象toArray返回int数组快
 * @Author Mr.Cui
 * @Date 2022/6/3
 */
public class array_06better {

    public int[] intersect(int[] nums1, int[] nums2) {
        int len1 = nums1.length, len2 = nums2.length;
        int len = len1 < len2 ? len1 : len2;
        int[] ans = new int[len];
        if (len1 == 0 || len2 == 0) {  //处理边界条件
            return ans;
        }
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int i = 0, j = 0, k = 0;
        while (i < len1 && j < len2) {
            if (nums1[i] == nums2[j]) {
                ans[k++] = nums1[i];
                i++;
                j++;
            } else if (nums1[i] < nums2[j]) {
                i++;
            } else {
                j++;
            }
        }
        return Arrays.copyOfRange(ans, 0, k);
    }


//    作者:刷题侠
//    链接:https://leetcode.cn/leetbook/read/top-interview-questions-easy/x2y0c2/?discussion=L1fh1Z
//    来源:力扣(LeetCode)
//    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
}

7.加一

这个题自己没写出来
1.这个解法的思路是从后面向前面遍历,只要小于就那么就不会进到下一位,也就是说加一后这个数的位数没有发生变化,那么直接返回该数组即可,
2.否则发生进位,将该为置为0,
3.如果遍历完数组的话说明该数所有位都是9,那么需要进位,只要将数组的第一位置为1其他都为0,返回该数组即可

package primary.array;

import java.util.Arrays;

/**
 * @Description:加一
 * @Author Mr.Cui
 * @Date 2022/6/3
 */
public class array_07 {

    public static int[] plusOne(int[] digits) {
        int length = digits.length;
        for (int i = length - 1; i >= 0; i--) {
            if (digits[i] != 9) {
                //如果数组当前元素不等于9,直接加1
                //然后直接返回
                digits[i]++;
                return digits;
            } else {
                //如果数组当前元素等于9,那么加1之后
                //肯定会变为0,我们先让他变为0
                digits[i] = 0;
            }
        }
        //除非数组中的元素都是9,否则不会走到这一步,
        //如果数组的元素都是9,我们只需要把数组的长度
        //增加1,并且把数组的第一个元素置为1即可
        int temp[] = new int[length + 1];
        temp[0] = 1;
        return temp;


    }

    public static void main(String[] args) {
        int[] digits={9,9,9,9};
        System.out.println(Arrays.toString(plusOne(digits)));
    }
}

8.移动零

8.1

我的思路是创建i和j分别标识一前一后,符合对应条件则进行对应操作
1.nums[i]==0&&nums[j]!=0:互换这俩个的值并且同时移动下标
2.nums[i]!=0:包括了nums[j]等于零和不等于零的情况,同时移动下标,不进行任何操作
3.剩下的情况只剩两个位置都是0的时候,不交换,只将j向后平移

package primary.array;

import java.util.Arrays;

/**
 * @Description:移动零
 * @Author Mr.Cui
 * @Date 2022/6/3
 */
public class array_08 {
    public static int[] moveZeroes(int[] nums) {
        int l=nums.length;
        if (l==1){
            return null;
        }
        else {
            int i=0;
            int j=1;
            while(j<l){
                if(nums[i]==0&&nums[j]!=0){ //符合该条件时互换这俩位置上的值
                    int x=nums[j];
                    nums[j]=nums[i];
                    nums[i]=x;
                    i++;
                }
                else if (nums[i]!=0){ //包括了nums[j]等于零和不等于零的情况
                    i++;
                }
                //剩下的情况只剩两个位置都是0的时候,不交换,只将i和j向后平移

                j++;
            }
        }
        System.out.println(Arrays.toString(nums));
        return nums;
    }

    public static void main(String[] args) {
        int[] nums={0,0,0,1};
        nums=moveZeroes(nums);
    }
}

8.2other

这个方法的思路是;把所有非0的数推到数组的前面,后面的元素全部置为0

package primary.array;

/**
 * @Description:该方法真是绝绝子,不需要考虑特殊情况,直接用后面的非零整数覆盖掉前面的,后面的直接全部改为0
 * @Author Mr.Cui
 * @Date 2022/6/3
 */
public class array_08better {
    public void moveZeroes(int[] nums) {
        if(nums==null) {
            return;
        }
        //第一次遍历的时候,j指针记录非0的个数,只要是非0的统统都赋给nums[j]
        int j = 0;
        for(int i=0;i<nums.length;++i) {
            if(nums[i]!=0) {
                nums[j++] = nums[i];
            }
        }
        //非0元素统计完了,剩下的都是0了
        //所以第二次遍历把末尾的元素都赋为0即可
        for(int i=j;i<nums.length;++i) {
            nums[i] = 0;
        }
    }
}

9.两数之和

9.1me

两次循环,一层计算和减去第一个数组的值和第二层的数组去比较得出所求

package primary.array;

import java.util.Arrays;

/**
 * @Description:
 * @Author Mr.Cui
 * @Date 2022/6/4
 */
public class array_09 {
    public static int[] twoSum(int[] nums, int target) {
        for(int i=0;i< nums.length-1;i++){
            for(int j=i+1;j<nums.length;j++){
                if(target-nums[j]==nums[i]){
                    return new int[]{i,j};
                }
            }

        }
        return null;
    }

    public static void main(String[] args) {
        int[] a={2,7,11,15};
        int target=9;
        int[] target1=twoSum(a,target);
        System.out.println(Arrays.toString(target1));
    }
}

9.2other

该作者利用哈希映射来降低时间复杂度

package primary.array;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:该作者利用哈希映射来降低时间复杂度
 * @Author Mr.Cui
 * @Date 2022/6/4
 */
public class array_09better {
    public static int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i< nums.length; i++) {
            if(map.containsKey(target - nums[i])) {
                return new int[] {map.get(target-nums[i]),i};
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("No two sum solution"); //非法参数异常
    }

    public static void main(String[] args) {
        int[] a={2,7,11,15};
        int target=9;
        int[] target1=twoSum(a,target);
        System.out.println(Arrays.toString(target1));
    }
//    作者:guanpengchn
//    链接:https://leetcode.cn/problems/two-sum/solution/jie-suan-fa-1-liang-shu-zhi-he-by-guanpengchn/
//    来源:力扣(LeetCode)
//    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
}

10.有效的数独

10.1

创建三个数组分别标识,某位数字是否已经被摆放,记录某列,某位数字是否已经被摆放,// 记录某 3x3 宫格内,某位数字是否已经被摆放,如果遍历到哪个数该数所在位置已经为true那么则不是有效的数独,反之则为有效的数独

package primary.array;

/**
 * @Description:有效的数独
 * @Author Mr.Cui
 * @Date 2022/6/5
 */
public class array_10 {

    public boolean isValidSudoku(char[][] board) {
        // 记录某行,某位数字是否已经被摆放
        boolean[][] row = new boolean[9][9]; //boolean数组的默认值为false
        // 记录某列,某位数字是否已经被摆放
        boolean[][] col = new boolean[9][9];
        // 记录某 3x3 宫格内,某位数字是否已经被摆放
        boolean[][] block = new boolean[9][9];

        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] != '.') {
                    int num = board[i][j] - '0'-1;//减0是为了转化为整数.减一是为了让它和数组的下标对应上
                    int blockIndex = i / 3 * 3 + j / 3; // 计算属于第几个3x3宫格
                    if (row[i][num] || col[j][num] || block[blockIndex][num]) {
                        return false;
                    } else {
                        row[i][num] = true;
                        col[j][num] = true;
                        block[blockIndex][num] = true;
                    }
                }
            }
        }
        return true;
    }

}

10,2

该算法用到了位运算,思路如下

在这里插入图片描述

package primary.array;

/**
 * @Description:利用位运算
 * @Author Mr.Cui
 * @Date 2022/6/5
 */
public class array_10better {
    public boolean isValidSudoku(char[][] board) {
        int[] line = new int[9];
        int[] column = new int[9];
        int[] cell = new int[9];
        int shift = 0;
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                //如果还没有填数字,直接跳过
                if (board[i][j] == '.')
                    continue;
                shift = 1 << (board[i][j] - '0');
                int k = (i / 3) * 3 + j / 3;
                //如果对应的位置只要有一个大于0,说明有冲突,直接返回false
                if ((column[i] & shift) > 0 || (line[j] & shift) > 0 || (cell[k] & shift) > 0)
                    return false;
                column[i] |= shift;
                line[j] |= shift;
                cell[k] |= shift;
            }
        }
        return true;

    }

//    作者:数据结构和算法
//    链接:https://leetcode.cn/leetbook/read/top-interview-questions-easy/x2f9gg/?discussion=LKIXWG
//    来源:力扣(LeetCode)
//    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
}

11.旋转镜像

根据规律总结出来新的坐标横坐标为原坐标的纵坐标,纵坐标等于正方形的边长减一再减原横坐标,因为旋转90度,所以分成四组

package primary.array;

/**
 * @Description:旋转镜像
 * @Author Mr.Cui
 * @Date 2022/6/5
 */
public class array_11 {
    /*
     * 0,0   1,0     2,0         0,2     0,1     0,0
     *
     * 0,1   1,1     2,1 ===>>>  1,2     1,1     1,0
     *
     * 0,2   1,2     2,2         2,2     2,1     2,0
     * */
    public void rotate(int[][] matrix) {

        int length = matrix.length;
        //因为是对称的,只需要计算循环前半行即可
        int n = matrix.length;
        for (int i = 0; i < n / 2; ++i) {
            for (int j = 0; j < (n + 1) / 2; ++j) {
                int temp = matrix[i][j]; //因为旋转的话四个数要循环替换,所以定义一个数来存取第一个数,防止被覆盖掉
                matrix[i][j] = matrix[n - j - 1][i]; //根据规律总结出来新的坐标横坐标为原坐标的纵坐标,纵坐标等于正方形的边长减一减原横坐标
                matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1];
                matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1];
                matrix[j][n - i - 1] = temp;
            }
        }

//        作者:LeetCode-Solution
//        链接:https://leetcode.cn/problems/rotate-image/solution/xuan-zhuan-tu-xiang-by-leetcode-solution-vu3m/
//        来源:力扣(LeetCode)
//        著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
    }


}

LeetCode卡片探索-初级算法 卡片探索-初级算法数组删除排序数组中的重复项买卖股票的最佳时机 II字符串链表树排序和搜索动态规划设计问题数学其他 LeetCode上知识卡片之初级算法的刷题记录 数组 删除排序数组中的重复项 难点在于原地删除的同时不想时间复杂度太高的话,可以考虑双指针。一个指针遍历数组判断是否为重复元素,一个指针用来搜集不重复元素并把他们安排到数组前列。 class Solution: def removeDuplicates(self, nums: List[int]) -> int: i 阅读详情

相关推荐

leecode刷题

1.两数之和 题目描述: 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 示例 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1] 方法1:暴力解法 int* twoSu

小跑 1308

LeetCode-力扣-870-优势洗牌-c++

给定两个大小相等的数组 nums1 和 nums2,nums1 相对于 nums2 的优势可以用满足 nums1[i] > nums2[i]的索引 i 的数目来描述。返回 nums1 的任意排列,使其相对于 nums2 的优势最大化。

LinShaoQINg's_bloGGGGG 496

Unity实时控制佳能单反拍照全流程(附EDSDK 3.6.1配置避坑指南)

本文详细介绍了在Unity中实时控制佳能单反相机进行拍照的完整流程,重点提供了EDSDK 3.6.1的配置与避坑指南。内容涵盖从SDK获取、环境搭建、相机初始化、参数设置到实现拍照控制,并深入探讨了实时取景的延迟优化方案与资源管理,旨在帮助开发者高效集成专业相机,提升AR/VR及摄影测量等应用的视觉输入质量。

go5gopher的博客 184

图像压缩编码码matlab实现——JSjpeg

function y = jpegencode(x, quality) %jpegencode函数用来压缩图像,x为输入图像 %quality决定了截去的系数和压缩比 error(nargchk(1, 2, nargin)); %检查输入参数 if nargin < 2 quality = 1; %默认时 quality为1 end x = double(x) - 128; %像素层次移动-128 [xm, xn] = size(x); %得到像素尺寸 t = dctmtx...

FPGA/MATLAB学习教程/源码/项目合作开发 6958

[终于解决]Ubuntu14.04 32位安装移动网卡(0bda:b711)驱动8188gu tplink-WN726n

大致梳理一下问题解决的流程 首先,在台式机做了双系统,台式机只有一个网线接口,由于项目要求,需要占用网口传输数据,所以用之前买的tplink-WN726n免驱版2.0的移动网卡 【note】免驱版只能在Windows下安装使用,在Ubuntu系统中无法使用,所以,需要另辟蹊径。 找了很多资料,尝试很多方法,有的复杂有的简单,终于解决。 【思路】首先在Ubuntu系统中输入lsusb,查看是否检测到USB网卡设备。然后从Github中复制代码,构建,安装,然后modprobe一下,到前面那步还不行,就再来一步

瑞o 1万+

香橙派5Max + Realsense D435i + Fast-Drone-250:手把手教你搭建一个完整的无人机视觉开发环境

本文详细介绍了如何利用香橙派5Max、Realsense D435i深度相机和Fast-Drone-250项目搭建完整的无人机视觉开发环境。从硬件连接到ROS配置,再到项目部署与性能优化,提供全栈式实战指南,助力开发者快速实现SLAM算法验证和自主导航功能开发。

weixin_30879169的博客 462

【日常系列】LeetCode《9·哈希查找篇》

通过索引随机访问数组元素时间复杂度:'O(1)lc 771:宝石与石头提示:jewels 和 stones 仅由英文字母组成jewels 中的所有字符都是 唯一的。

qq_42889517的博客 287

直流有刷电机控制 - 驱动电路(二)

1.如图所示为最常见的推挽驱动电路,我附加了具有正反转功能的电机驱动控制,正反转是由两个继电器组成。使用推挽电路来驱动NMOS管时充电电流和放电电流都很大,因此NMOS管导通快,关断也快,而且NMOS温度不会很高。下面来介绍一下该电路的原理。(1)PWM_MCU是由单片机给出的PWM波信号,该信号是由一些列高低电平的方波构成。当信号为高电平的时候Q3导通,经过R47再到Q5的g极,此时mos导通,如果是K1闭合是正转那么K2闭合就是反转。(2)当PWM低电平时使得Q3关断,Q6导通。

u011030644的博客 4720

列表操作总结

针对列表的增删改查 如有错误联系xiaokangk1@gmail.com 定义一个字符串列表 name_list = [“zhansan”, “lisi”, “wangwu”, “maliu”, “gaoping”, “lisi”] 1.增加 1.1 指定位置增加元素 name_list.insert(index,items) name_list.insert(1, “xiaokang”) pri...

weixin_44161448的博客 560

量子城域网建设设备系列(三):网络管理系统(NMS)

本文对量子网络中的网络管理系统进行了初步的介绍。

量子领域相关话题 2013

稚晖君Dummy机械臂CAN总线控制详解:从代码到实战(附常见问题排查)

本文深入解析了稚晖君Dummy机械臂的CAN总线控制技术,从协议设计到代码实现,详细介绍了CAN总线在机械臂控制中的核心价值、通信协议栈设计、运动控制指令实现及常见问题排查方法。通过实战案例和代码示例,帮助开发者快速掌握机械臂CAN总线控制的关键技术。

uuu88的博客 295

【EduCoder】数据结构与算法—查找

数据结构与算法—查找第1关:实现折半查找第2关:实现散列查找 第1关:实现折半查找 任务描述: 本关要求通过补全函数BSL_FindKey来实现在已排序的顺序表中查找关键码值为key的结点并返回该结点的编号。 相关知识 折半查找通常是针对顺序存储的线性表,线性表的结点按关键码从小到大排序,后面称之为折半查找的顺序表。为了简化讨论,假设折半查找的顺序表中每个结点只含一个关键码,关键码为整数。图 1 给出了一个存储了 4 个关键码的折半查找的顺序表的存储结构图。 下面描述了线性表顺序存储的一种实现方案。该实现方

m0_55205575的博客 4483

python实现序列比对之Needleman-wunsch算法 (附完整源码)

python实现序列比对之Needleman-wunsch算法 (附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 461

Leecode初级算法C++题解(数组篇)

数组篇 1.从排序数组中删除重复项 题目要求:给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度。 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。 算法说明:简答题,因为要求空间复杂度O(1),不能额外创建数组,可以创建个变量res保存不一样的数的长度。 class Solution { public: ...

不爱学习的壳的博客 899

通过WorkVisual连接KUKA机器人的具体方法

通过WorkVisual连接KUKA机器人的具体方法

Robot_PLC_HMI_Automation 6843

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Leecode 题集

题目 给定一个二进制数组, 计算其中最大连续 1 的个数。 解答: class Solution { public int findMaxConsecutiveOnes(int[] nums) { int sum=0; for(int i=0;i<nums.length;i++){ if(nums[i]==1){ sum++; }else{ if(

lena blog 1470

怀旧版电脑GBC模拟器

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

LeetCode刷题笔记(一)——初级算法——数组

❤ 2021.8.26 ❤ 知道LeetCode这个东西有一两年了,一见到就很有学习的冲动,但是自己太菜,一直做比较简单的硬件开发,没怎么接触过算法数据结构之类的东西,当时选了最简单的第一题就被劝退了,甚至我都不知道答题窗口里的函数结构怎么用。。。 前两天师妹心血来潮要刷LeetCode,我趁机也刷一刷也好有人能讨论讨论。 →→→时光倒流! ❤ 2021.8.24 ❤ 今天的题目是 删除排序数组中的重复项 芜湖挺简单的,但是不会。。。 根据我多年来的考研经验,不会的题先背答案再说! 答

ooorczgc的博客 849

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

LeetCode刷题指南:用C语言征服50道经典算法题

LeetCode 作为全球知名的算法练习平台,提供了大量经典的算法题目。使用 C 语言刷题,不仅可以加深对算法的理解,还能提升对底层编程的掌握。本指南将带领你用 C 语言征服 50 道经典算法题,为你的技术能力提升助力。

星辰夜语的博客 2024

<LeetCode天梯>“交个朋友&一起变强”之攻略集合部分三 | 初级算法 | Python

????作者简介:大家好,我是车神哥,府学路18号的车神???? ⚡About—>车神:从寝室到实验室最快3分钟,最慢3分半(那半分钟其实是等红绿灯) ????个人主页:应无所住而生其心的博客_府学路18号车神_优快云博客 ????点赞➕评论➕收藏 == 养成习惯(一键三连)???? ????本系列主要以刷LeetCode(力扣)网站的各类题为标准,实现自我能力的提升为目标⚡ ⚡希望大家多多支持????~一起加油 ???? 专栏《LeetCode天梯》 其他专栏: 《LeetCode天梯》 《

车手只需要车和手,压力来自轮胎 1443

【leecode刷题】初级算法-数组

1、删除排序数组中的重复项 class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums)==0: return 0 else: i = 0 for j in range(l

思南的博客 346

刷完 300 道 LeetCode 题后,我膨胀到要飘起来了!纯正 Java 版

优快云 的小伙伴们,大家好,我是爱学习爱分享的沉默王二。 迫不及待的小伙伴可以直接拖到文末,拉取离线版的下载地址,无套路无解压密码,我整理了将近一周的时间。 不经意间,在 GitHub 上发现了一个 1G 棒的 LeetCode 刷题笔记,重点来了,是纯正的 Java 版。我见过很多牛逼的刷题笔记,有 Go 版的,有 C++ 版的,唯独没有 Java 版的,所以这次,我感觉找到了宝藏! 其实私下里很多小伙伴问我有没有 Java 版的,一开始我觉得刷题嘛,用啥语言刷题根本不重要,重要的是解题的思路。但看到这

沉默王二 3万+

【C语言刷题——Leetcode12道题】带你起飞,飞进垃圾堆

刷题之——Leetcode12道简单题,通过这12道简单题,让你对Leetcode有所新的理解,增强自己的做题能力。下面,直接进入我们的题目。👇这道题Leetcode难度归类为中等,但是我感觉我们撑一撑应该还是能做得出来的(bushi):这里的变量为了方便说明就使用我做题过程中命名的名字了🌹解题思路:首先,我们定义一个变量(eor)初始化为0去遍历按位异或数组中的所有元素,此时得到的是只出现一次的两个元素的二进制异或结果。然后去对二进制的结果进行处理:对于两个不同的数字,异或出来的二进制结果中为1的话说..

weixin_60478154的博客 1万+

Leecode初级算法C++题解(字符串篇)

字符串篇 力扣初级算法链接 1.反转字符串(leecode第344题) 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。不要给另外的数组分配额外的空间,你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。 你可以假设数组中的所有字符都是 ASCII 码表中的可打印字符。 1.1 双指针法 算法:就是将头尾的元素互换,双指针,start和en...

不爱学习的壳的博客 1094

LeetCode初级算法训练-数组(完成)

简介 LeetCode初级算法简介 本来想重初中级和企业面试算法开始的,但是最后还是选择从基础的开始,因为我们并不是为了刷题而刷题,而是在刷题过程中锻炼一种算法思维,在大量的训练之后形成一种对算法的独特见解,培养那种对算法的的敏感度,看到题目,大脑中可以浮现一个解题蓝图,而且从初级开始慢慢建立信心,而且这也是在为后边复杂算法的解题思路打基础。 如果你也想训练自己的算法思维,也可以加入我,从初级算法开始,开启你的算法之旅:初级算法。 切忌:不要在看完题目后直接就看答案,然后去背题,这样行成的算法记忆是不牢固的

Darksider博客 454

<LeetCode天梯>攻略集合部分 | 初级算法 | Python(U can save)

????作者简介:大家好,我是车神哥,府学路18号的车神???? ????个人主页:应无所住而生其心的博客_府学路18号车神_优快云博客 ????点赞➕评论➕收藏 == 养成习惯(一键三连)???? ????本系列主要以刷LeetCode(力扣)网站的各类题为标准,实现自我能力的提升为目标⚡ ⚡希望大家多多支持????~一起加油 ???? 专栏《LeetCode天梯》 今天终于刷完了初等算法->数组篇,更新一下目录吧~ 第一节刷完,用了14天,坚持每一天,车神哥得了340分。你得了多少分呢,还

车手只需要车和手,压力来自轮胎 762

★ 算法OJ题 ★ 前缀和算法(上)

★ 算法OJ题 ★ 前缀和算法(上)

2302_80328146的博客 3973
上一篇: Description: Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded dat
下一篇: LeeCode初级算法字符串部分九道题
low_key_
博客等级 码龄7年 8粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值