add
This commit is contained in:
parent
cd363ddc8e
commit
419335158e
37
5.leetcode/src/com/fanxb/common/Q149.java
Normal file
37
5.leetcode/src/com/fanxb/common/Q149.java
Normal 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}}));
|
||||||
|
}
|
||||||
|
}
|
29
5.leetcode/src/com/fanxb/common/Q1833.java
Normal file
29
5.leetcode/src/com/fanxb/common/Q1833.java
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ import java.util.*;
|
|||||||
**/
|
**/
|
||||||
public class Q401 {
|
public class Q401 {
|
||||||
private static Map<Integer, LinkedList<String>> map = new HashMap<>(10);
|
private static Map<Integer, LinkedList<String>> map = new HashMap<>(10);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (int i = 0; i <= 11; i++) {
|
for (int i = 0; i <= 11; i++) {
|
||||||
for (int j = 0; j <= 59; j++) {
|
for (int j = 0; j <= 59; j++) {
|
||||||
@ -20,6 +21,7 @@ public class Q401 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int count(int x) {
|
private static int count(int x) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (x > 0) {
|
while (x > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user