package 每日算法学习打卡.算法打卡.七月份.七月三十一号;importjava.util.Arrays;publicclass test1 {//子矩阵的最大累加和publicstaticvoidmain(String[] args){int[][] matrix ={{}};System.out.println(maxSum(matrix));}publicstaticintmaxSum(int[][] matrix){int beginRow =0;if(matrix.length ==0|| matrix[0].length ==0){return0;}intM= matrix.length;intN= matrix[0].length;int[] sums =newint[N];int max =0;while(beginRow <M){for(int i = beginRow; i <M; i++){for(int j =0; j <N; j++){
sums[j]+= matrix[i][j];}int t =findByDp(sums);if(t > max){
max = t;}}//快速将sums的每个元素都设为0Arrays.fill(sums,0);
beginRow++;}return max;}//使用递推法 来求子数组的最大累加和staticintfindByDp(int[] arr){int sumI = arr[0];int maxSum = sumI;for(int i =1; i < arr.length; i++){if(sumI >=0){
sumI+= arr[i];}else{
sumI = arr[i];}if(sumI > maxSum){
maxSum = sumI;}}return maxSum;}}
矩阵运算-乘法
整体代码
package 每日算法学习打卡.算法打卡.七月份.七月三十一号;publicclass test2 {publicstaticvoidmain(String[] args){}/*
* 矩阵乘法
* 矩阵1为n*m矩阵,矩阵2为m*p矩阵
* 结果为n*p矩阵
*
* */publicstaticlong[][]matrixMultiply(long[][] m1,long[][] m2){finalint n = m1.length;finalint m = m1[0].length;if(m != m2.length)thrownewIllegalArgumentException();finalint p = m2[0].length;long[][] result =newlong[n][p];//新矩阵的行数为m1的行数,列数为m2的列数for(int i =0; i < n; i++){//m1的每一行for(int j =0; j < p; j++){//m2的每一列for(int k =0; k < m; k++){
result[i][j]+= m1[i][k]* m2[k][j];}}}return result;}}
检测字符串是否有重复字符
整体代码
package 每日算法学习打卡.算法打卡.七月份.七月三十一号;importcom.sun.xml.internal.ws.util.StringUtils;publicclass test3 {//检测字符串是否有重复字符publicstaticvoidmain(String[] args){String s ="asdff";System.out.println(checkDifferent(s));}publicstaticbooleancheckDifferent(String s){if(s ==null|| s.isEmpty()){returntrue;}int[] flag =newint[128];for(int i =0; i < s.length(); i++){int c =(int) s.charAt(i);if(flag[c]>0)returnfalse;else flag[c]++;}returntrue;}}
反转字符串
整体代码
package 每日算法学习打卡.算法打卡.七月份.七月三十一号;publicclass test4 {publicstaticvoidmain(String[] args){String s ="adfa";System.out.println(reverseString(s));}publicstaticStringreverseString(String s){int len = s.length();char[] c =newchar[len];for(int i =0;i<len;i++){
c[i]= s.charAt(len-1-i);}returnnewString(c);}//使用java中自带的api来进行翻转publicstaticStringreverseString1(String a){StringBuffer sb =newStringBuffer(a);return sb.reverse().toString();}}
概述
一个基本由自己实现的JPEG有损图像压缩编码器,基于JFIF(JPEG文件交换格式)标准:
色彩空间转换(RGB to YUV)色度抽样(采样因子4:2:0)MCU分块(16x16的最小编码单元&…