This commit is contained in:
Mrhongxing committed 2026-10-15 00:36:24 +08:00
1 parent 8d3d783d0a
commit d424ed1891
3 files changed
+163 -1

No files matched your search

+98
View File
@@ -0,0 +1,98 @@
package com.hong.www;
import java.util.HashMap;
public class A149 {
public int maxPoints(int[][] points) {
int finalcount = 0;
for (int i = 0; i < points.length; i++) {
HashMap<Float, Integer> K = new HashMap<>();
for (int j = i+1 ; j < points.length; j++) {
float k;
if(points[i][0] - points[j][0]!=0){
if(points[i][1] - points[j][1]==0){
k = 0;
}else{
k = (float)(points[i][1] - points[j][1]) / (points[i][0] - points[j][0]);
}
}else{
k = Float.POSITIVE_INFINITY; // Use a special value for vertical lines
}
if (K.containsKey(k)) {
if (K.get(k) + 1 >= finalcount) {
finalcount = K.get(k) + 1;
}
K.put(k, K.get(k) + 1);
} else {
K.put(k, 1);
if(finalcount<1){
finalcount=1;
}
}
}
}
/* HashMap<Float, HashMap<Float, Integer>> KB = new HashMap<>();
for (int i = 0; i < points.length; i++) {
for (int j = i ; j < points.length; j++) {
if (i != j) {
float k;
float b;
if((points[i][0] - points[j][0])!=0){
k = (points[i][1] - points[j][1]) / (points[i][0] - points[j][0]);
b = points[i][1] - k * points[i][0];
}else{
k=0;
b=0;
}
if (KB.containsKey(k)) {
if (KB.get(k).containsKey(b)) {
if (KB.get(k).get(b) + 1 >= finalcount) {
finalcount = KB.get(k).get(b) + 1;
}
KB.get(k).put(b, KB.get(k).get(b) + 1);
} else {
KB.get(k).put(b, 1);
}
} else {
HashMap<Float, Integer> temp = new HashMap<>();
temp.put(b, 1);
KB.put(k, temp);
}
}
}
}
if(finalcount==0&&points.length==1){
finalcount=1;
}else if(finalcount==0){
finalcount=2;
}
int count = 2;
while (count<finalcount){
count++;
int tempcount = 0;
for(int c=1;c<count;c++){
tempcount+=c;
}
if(tempcount==finalcount){
finalcount=count;
}
} */
return finalcount+1;
}
public static void main(String[] args) {
A149 solution = new A149();
int[][] points = {{1,1},{2,2},{3,3},{4,4},{5,5},{1,2},{2,3},{3,4}};
int result = solution.maxPoints(points);
System.out.println("Maximum number of points on a line: " + result);
}
}
+64
View File
@@ -0,0 +1,64 @@
package com.hong.www;
import java.util.*;
public class A76 {
public int temp(char[] chars, HashMap<Character, Integer> temp, HashMap<Character, Integer> temp2, HashMap<Character, Integer> temp3, ArrayList<String> finalList, int left, int right, CharSequence s) {
if (temp.containsKey(chars[right])) {
temp2.put(chars[right], temp2.getOrDefault(chars[right], 0) + 1);
if (temp2.get(chars[right]) - temp.get(chars[right]) >= 0) {
temp3.put(chars[right], 0);
}
}
int xx = 0;
for (int x : temp3.values()) {
xx += x;
}
if (xx == 0) {
finalList.add((String) s.subSequence(left, right + 1));
temp2.put(chars[left], temp2.get(chars[left]) - 1);
if (temp2.get(chars[left]) - temp.get(chars[left]) >= 0) {
temp3.put(chars[left], 0);
}else{
temp3.put(chars[left], 1);
}
for (int j = left + 1; j <= right; j++) {
if (temp.containsKey(chars[j])) {
left = j;
break;
}
}
left=temp(chars, temp, temp2, temp3, finalList, left, right, s);
}
return left;
}
public String minWindow(String s, String t) {
ArrayList<String> list = new ArrayList<>();
char[] chars = s.toCharArray();
char[] chart = t.toCharArray();
HashMap<Character, Integer> temp = new HashMap<>();
HashMap<Character, Integer> temp2 = new HashMap<>();
HashMap<Character, Integer> temp3 = new HashMap<>();
ArrayList<String> finalList = new ArrayList<>();
for (char x : chart) {
temp.put(x, temp.getOrDefault(x, 0) + 1);
temp3.put(x, 1);
}
int left = 0;
int right = 0;
while (right < chars.length) {
left=temp(chars, temp, temp2, temp3, finalList, left, right, s);
right++;
}
return "xx";
}
public static void main(String[] args) {
A76 a76 = new A76();
String s = "ADOBECODEBANC";
String t = "ABC";
System.out.println(a76.minWindow(s, t));
}
}