1.3
This commit is contained in:
1 parent
ff8c92b6b5
commit
864fc9e663
5 files changed
+168
No files matched your search
@@ -0,0 +1,58 @@
|
|||||||
|
package com.hong.www;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class A2565 {
|
||||||
|
public int minimumScore(String s, String t) {
|
||||||
|
int n = s.length(), m = t.length();
|
||||||
|
|
||||||
|
// pre[i] = t 前 i 个字符最少用 s 的前多少个字符
|
||||||
|
int[] pre = new int[m + 1];
|
||||||
|
Arrays.fill(pre, -1);
|
||||||
|
pre[0] = 0;
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < m; i++) {
|
||||||
|
while (j < n && s.charAt(j) != t.charAt(i))
|
||||||
|
j++;
|
||||||
|
if (j == n)
|
||||||
|
break;
|
||||||
|
j++;
|
||||||
|
pre[i + 1] = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
// suf[i] = t 后缀从 i 开始,s 从哪个位置开始能匹配
|
||||||
|
int[] suf = new int[m + 1];
|
||||||
|
Arrays.fill(suf, -1);
|
||||||
|
suf[m] = n;
|
||||||
|
j = n - 1;
|
||||||
|
for (int i = m - 1; i >= 0; i--) {
|
||||||
|
while (j >= 0 && s.charAt(j) != t.charAt(i))
|
||||||
|
j--;
|
||||||
|
if (j < 0)
|
||||||
|
break;
|
||||||
|
j--;
|
||||||
|
suf[i] = j + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 枚举删除区间 [l, r-1],条件 pre[l] <= suf[r]
|
||||||
|
int ans = m;
|
||||||
|
int r = 0;
|
||||||
|
for (int l = 0; l <= m; l++) {
|
||||||
|
if (pre[l] == -1)
|
||||||
|
continue;
|
||||||
|
while (r <= m && (suf[r] == -1 || pre[l] > suf[r]))
|
||||||
|
r++;
|
||||||
|
if (r <= m) {
|
||||||
|
if(r<l) r=l;
|
||||||
|
ans = Math.min(ans, r - l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
A2565 a2565 = new A2565();
|
||||||
|
System.out.println(a2565.minimumScore("adebddaccdcabaade", "adbae"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hong.www;
|
||||||
|
|
||||||
|
public class A312 {
|
||||||
|
public int maxCoins(int[] nums) {
|
||||||
|
int[] numbers=new int[nums.length+2];
|
||||||
|
for(int i=0;i<nums.length;i++){
|
||||||
|
numbers[i+1]=nums[i];
|
||||||
|
}
|
||||||
|
numbers[0]=1;
|
||||||
|
numbers[numbers.length-1]=1;
|
||||||
|
int[][] dp=new int[nums.length+1][nums.length+2];
|
||||||
|
for(int len=2;len<numbers.length;len++){
|
||||||
|
for(int from=0;from<numbers.length-len;from++){
|
||||||
|
for(int max=from+1;max<from+len;max++){
|
||||||
|
dp[from][from+len]=Math.max(dp[from][from+len], dp[from][max]+numbers[from]*numbers[max]*numbers[from+len]+dp[max][from+len]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dp[0][nums.length+1];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.hong.www;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
class A425 {
|
||||||
|
public int findMinArrowShots(int[][] points) {
|
||||||
|
Arrays.sort(points, (a, b) ->Integer.compare(a[1], b[1]));
|
||||||
|
int count = 1;
|
||||||
|
int end = points[0][1];
|
||||||
|
for (int i = 1; i < points.length; i++) {
|
||||||
|
if(points[i][0] > end){
|
||||||
|
count++;
|
||||||
|
end = points[i][1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
A425 a425=new A425();
|
||||||
|
int[][] points={{10,16},{2,8},{1,6},{7,12}};
|
||||||
|
System.out.println(a425.findMinArrowShots(points));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.hong.www;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class A84 {
|
||||||
|
public int largestRectangleArea(int[] heights) {
|
||||||
|
if(heights.length==1){
|
||||||
|
return heights[0];
|
||||||
|
}
|
||||||
|
int currentMax = 0;
|
||||||
|
int finalMax = 0;
|
||||||
|
ArrayList<Integer> maxs=new ArrayList<>();
|
||||||
|
for(int i = 0; i < heights.length; i++) {
|
||||||
|
if(heights[i]>currentMax){
|
||||||
|
maxs.clear();
|
||||||
|
maxs.add(i);
|
||||||
|
currentMax=heights[i];
|
||||||
|
}else if(heights[i]==currentMax){
|
||||||
|
maxs.add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int x:maxs){
|
||||||
|
int currectMin=Integer.MAX_VALUE;
|
||||||
|
//int max=0;
|
||||||
|
for(int i=x-1;i>=0;i--){
|
||||||
|
if(heights[i]<=currectMin){
|
||||||
|
currectMin=heights[i];
|
||||||
|
if(currectMin*(x-i+1)>finalMax){
|
||||||
|
finalMax=currectMin*(x-i+1);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(currectMin*(x-i+1)>finalMax){
|
||||||
|
finalMax=currectMin*(x-i+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currectMin=Integer.MAX_VALUE;
|
||||||
|
for(int i=x+1;i<heights.length;i++){
|
||||||
|
if(heights[i]<=currectMin){
|
||||||
|
currectMin=heights[i];
|
||||||
|
if(currectMin*(i-x+1)>finalMax){
|
||||||
|
finalMax=currectMin*(i-x+1);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(currectMin*(i-x+1)>finalMax){
|
||||||
|
finalMax=currectMin*(i-x+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(finalMax==0){
|
||||||
|
return currentMax;
|
||||||
|
}
|
||||||
|
return finalMax;
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
A84 a84=new A84();
|
||||||
|
int[] heights={4,2};
|
||||||
|
System.out.println(a84.largestRectangleArea(heights));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.hong.www;
|
||||||
|
|
||||||
|
public class LCP69 {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user