add
This commit is contained in:
parent
1b4e864ca9
commit
cd363ddc8e
39
5.leetcode/src/com/fanxb/common/Q401.java
Normal file
39
5.leetcode/src/com/fanxb/common/Q401.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package com.fanxb.common;
|
||||||
|
|
||||||
|
import com.sun.tools.jconsole.JConsoleContext;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两数相加
|
||||||
|
*
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/6/1
|
||||||
|
**/
|
||||||
|
public class Q401 {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Q401().readBinaryWatch(1);
|
||||||
|
}
|
||||||
|
}
|
38
5.leetcode/src/com/fanxb/common/Q877.java
Normal file
38
5.leetcode/src/com/fanxb/common/Q877.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package com.fanxb.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 两数相加
|
||||||
|
*
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/6/1
|
||||||
|
**/
|
||||||
|
public class Q877 {
|
||||||
|
public boolean stoneGame(int[] piles) {
|
||||||
|
int l=0,r=piles.length-1;
|
||||||
|
long a=0,b=0;
|
||||||
|
//是否a选择
|
||||||
|
boolean aChange=true;
|
||||||
|
while (l<=r){
|
||||||
|
int res =piles[r]-piles[l];
|
||||||
|
if (res <= 0) {
|
||||||
|
//说明左边的不小于右边的
|
||||||
|
if(aChange){
|
||||||
|
a+=piles[l++];
|
||||||
|
}else{
|
||||||
|
b+=piles[l++];
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(aChange){
|
||||||
|
a+=piles[r--];
|
||||||
|
}else{
|
||||||
|
b+=piles[r--];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
aChange=!aChange;
|
||||||
|
}
|
||||||
|
return a>b;
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(new Q877().stoneGame(new int[]{5,3,4,5}));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user