classSolution{publicintmaximumLength(int[]nums){int res=0,k=2,dp[][]=newint[k][k];for(int a:nums){for(int b=0;b<k;b++){dp[b][a%k]=Math.max(dp[b][a%k],dp[a%k][b]+1);res=Math.max(res,dp[b][a%k]);}}returnres;}} 还是不熟悉dp。。。
代码是js写的,如下: 1varlengthOfLongestSubstring =function(str) {2if(str.length === 0)return0;3varmaxLen = 1; //maximum serial string length4varmaxIdx = 0; //the array sub-index of the last char in the result string5vartmpArr = [0]; //array to save the status data6for(vari ...
1publicclassSolution {2publicintfindDuplicate(int[] nums) {3intmin = 0, max = nums.length - 1;4while(min <=max){5//找到中间那个数6intmid = min + (max - min) / 2;7intcnt = 0;8//计算总数组中有多少个数小于等于中间数9for(inti = 0; i < nums.length; i++){10if(nums[i]...
Given a stringS, return the number of substrings of lengthKwith no repeated characters. Example 1: Input: S ="havefunonleetcode", K =5 Output:6 Explanation: There are 6 substrings they are : 'havef','avefu','vefun','efuno','etcod','tcode'. 1. 2. 3. 4. Example 2: Input...
Can you solve this real interview question? Find Maximum Non-decreasing Array Length - You are given a 0-indexed integer array nums. You can perform any number of operations, where each operation involves selecting a subarray of the array and replacing
Length and two values Linked Lists - Length & Count longest_palindrome Maze Runner Minimize Sum Of Array (Array Series #1) Most digits Multiply Word in String Name Array Capping New Cashier Does Not Know About Space or Shift Number Pairs Numbers to Letters Ordered Count of Characters Parse HTML...
length; i++){ row = moves[i][0]; column = moves[i][1]; //若是A,则是X,反之为O t[row][column] = (i%2 == 0) ? "X" : "O"; } //暴力求解 //如果井字棋中间为X if(t[1][1] == "X"){ //判断井字棋左斜对角、右斜对角、中间横行、中间竖行是否都是X if((t[0][...
length(); } } return res; } // 检查字母表的字母出现次数是否覆盖单词的字母出现次数 bool contains(vector<int>& chars_count, vector<int>& word_count) { for (int i = 0; i < 26; i++) { if (chars_count[i] < word_count[i]) { return false; } } return true; } // 统计 26 ...
=str1[index-iv.index]){continue@loop}}valnewResult=str2+str1.substring(str2.length-iv.index..str1.lastIndex)if(newResult.length<result.length||result==""){result=newResult}break}if(result==""){result=str1+str2}returnresult}}funmain(args:Array<String>){valinputArray=arrayOf("sssv",...
ref: https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/#/solutions */ public int kthSmallest(int[][] matrix, int k) { int n = matrix.length; int lo = matrix[0][0], hi = matrix[n-1][n-1]; while (lo <= hi) { ...