This commit is contained in:
fanxb 2021-07-07 11:22:45 +08:00
parent cd363ddc8e
commit 419335158e
3 changed files with 79 additions and 11 deletions

View File

@ -0,0 +1,37 @@
package com.fanxb.common;
/**
* Created with IntelliJ IDEA
* 寻找旋转排序数组中的最小值
* 地址 https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/
* 思路 需要找到分界点
*
* @author fanxb
* Date: 2020/6/11 9:56
*/
public class Q149 {
public int maxPoints(int[][] points) {
int max = 1;
for (int i = 0; i < points.length; i++) {
int[] a1 = points[i];
for (int j = i + 1; j < points.length; j++) {
int[] a2 = points[j];
int n = 2;
for (int k = j + 1; k < points.length; k++) {
int[] a3 = points[k];
if ((a2[1] - a1[1]) * (a3[0] - a1[0]) == (a3[1] - a1[1]) * (a2[0] - a1[0])) {
n++;
}
}
if (n > max) {
max = n;
}
}
}
return max;
}
public static void main(String[] args) {
System.out.println(new Q149().maxPoints(new int[][]{{1, 1}, {3, 2}, {5, 3}, {4, 1}, {2, 3}, {1, 4}}));
}
}

View File

@ -0,0 +1,29 @@
package com.fanxb.common;
import java.util.*;
/**
* 两数相加
*
* @author fanxb
* @date 2021/6/1
**/
public class Q1833 {
public int maxIceCream(int[] costs, int coins) {
Arrays.sort(costs);
int count = 0;
for (int i = 0; i < costs.length; i++) {
coins -= costs[i];
if (coins >= 0) {
count++;
} else {
break;
}
}
return count;
}
public static void main(String[] args) {
System.out.println(new Q1833().maxIceCream(new int[]{1, 3, 2, 4, 1}, 7));
}
}

View File

@ -11,26 +11,28 @@ import java.util.*;
* @date 2021/6/1
**/
public class Q401 {
private static Map<Integer, LinkedList<String>> map=new HashMap<>(10);
private static Map<Integer, LinkedList<String>> map = new HashMap<>(10);
static {
for(int i=0;i<=11;i++){
for(int j=0;j<=59;j++){
LinkedList<String> linkedList = map.computeIfAbsent(count(i)+count(j),k->new LinkedList<>());
linkedList.add(i+":"+(j<10?"0"+j:j));
for (int i = 0; i <= 11; i++) {
for (int j = 0; j <= 59; j++) {
LinkedList<String> linkedList = map.computeIfAbsent(count(i) + count(j), k -> new LinkedList<>());
linkedList.add(i + ":" + (j < 10 ? "0" + j : j));
}
}
}
private static int count(int x){
int count=0;
while (x>0){
x-=x&(-x);
private static int count(int x) {
int count = 0;
while (x > 0) {
x -= x & (-x);
count++;
}
return count;
}
public List<String> readBinaryWatch(int turnedOn) {
return map.getOrDefault(turnedOn,new LinkedList<String>());
return map.getOrDefault(turnedOn, new LinkedList<String>());
}
public static void main(String[] args) {