leecode更新

This commit is contained in:
markilue 2023-03-28 22:10:09 +08:00
parent a606e20bb2
commit ef108c1def
2 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,80 @@
package com.markilue.leecode.test;
import org.junit.Test;
import org.omg.CORBA.PUBLIC_MEMBER;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*@BelongsProject: Leecode
*@BelongsPackage: com.markilue.leecode.test
*@Author: markilue
*@CreateTime: 2023-03-28 19:27
*@Description: TODO
*@Version: 1.0
*/
public class TestByteDance {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
TestByteDance sc1 = new TestByteDance();
while (n-- > 0) {
int num = sc.nextInt();
int k = sc.nextInt();
int result = sc1.sovle(num, k);
if (result == -1) {
System.out.println(-1);
}
}
}
List<Integer> cur = new ArrayList<Integer>();
@Test
public void test() {
// System.out.println(Math.pow(2, 2));
// System.out.println((int) Math.pow(2, 2));
// System.out.println(-1);
System.out.println(sovle(10000, 500));
// cur.clear();
// System.out.println(sovle(96, 2));
}
public int sovle(int num, int k) {
if (cur.size() == k) {
if (num == 0) {
for (Integer integer : cur) {
System.out.print(integer + " ");
}
System.out.println();
return 0;
}
return -1;
}
for (int i = getI(num), z = 1 << i; i >= 0; i--, z >>= 1) {
cur.add(i);
if (sovle(num - z, k) == 0) return 0;
cur.remove(cur.size() - 1);
}
return -1;
}
public int getI(int num) {
return (int) (Math.log(num) / Math.log(2));
}
@Test
public void test1() {
System.out.println(1 << 3);
System.out.println(getI(9));
}
}

View File

@ -0,0 +1,47 @@
package com.markilue.leecode.test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
/**
*@BelongsProject: Leecode
*@BelongsPackage: com.markilue.leecode.test
*@Author: markilue
*@CreateTime: 2023-03-28 20:02
*@Description: TODO
*@Version: 1.0
*/
public class TestByteDance4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = Integer.parseInt(sc.nextLine());
String[] strings = new String[k];
for (int i = 0; i < k; i++) {
strings[i] = sc.nextLine();
}
int operate = Integer.parseInt(sc.nextLine());
String[] operates = new String[operate];
for (int i = 0; i < operate; i++) {
operates[i] = sc.nextLine();
}
}
public void sovle(String[] strings, String[] operate) {
HashMap<String, HashSet<String>> map = new HashMap<>();
//原始情况
for (String string : strings) {
String[] split = string.split("/");
for (String s : split) {
map.getOrDefault(s,new HashSet<>());
// map.put()
}
}
}
}