Compare commits
No commits in common. "b6e5672f09b0080a63a50cda30cb929b97ad820f" and "d9e64a81a6098abe421b1c338b5ecf7720be4d66" have entirely different histories.
b6e5672f09
...
d9e64a81a6
@ -14,6 +14,7 @@
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
@ -23,12 +24,6 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--jdbc Driver-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@ -38,6 +33,7 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- JPA API -->
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
|
@ -54,6 +54,5 @@ public class FactoryAndStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,11 +2,6 @@ package cn.whaifree.designPattern.kama.CreateType.AbstractFactoryPattern;
|
||||
|
||||
|
||||
public class AbstractFactoryPattern {
|
||||
/**
|
||||
* AbstractFactory--> ModernFactory --|
|
||||
* --> ClassicFactory --|-->Sofa OR Chair
|
||||
* @param args
|
||||
*/
|
||||
|
||||
// https://kamacoder.com/problempage.php?pid=1077
|
||||
public static void main(String[] args) {
|
||||
|
@ -1,57 +0,0 @@
|
||||
### 简单工厂
|
||||
|
||||
一个工厂生产多种产品
|
||||
|
||||
```java
|
||||
public static Product createProduct(String type) {
|
||||
if ("A".equalsIgnoreCase(type)) {
|
||||
return new ProductA();
|
||||
} else if ("B".equalsIgnoreCase(type)) {
|
||||
return new ProductB();
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown product type");
|
||||
}
|
||||
```
|
||||
|
||||
### 工厂方法
|
||||
|
||||
对工厂抽象
|
||||
|
||||
```java
|
||||
// 抽象工厂接口
|
||||
interface Factory {
|
||||
Product createProduct();
|
||||
}
|
||||
|
||||
// 具体工厂A
|
||||
class FactoryA implements Factory {
|
||||
@Override
|
||||
public Product createProduct() {
|
||||
return new ProductA();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Factory factory = new FactoryA();
|
||||
Product product = factory.createProduct();
|
||||
product.use(); // 输出: Using Product A
|
||||
}
|
||||
```
|
||||
|
||||
### 抽象工厂
|
||||
|
||||
对产品再次抽象出不同属性
|
||||
|
||||
```java
|
||||
// 产品族A接口
|
||||
interface AbstractProductA {
|
||||
void featureA();
|
||||
}
|
||||
// 具体产品A1
|
||||
class ProductA1 implements AbstractProductA {
|
||||
@Override
|
||||
public void featureA() {
|
||||
System.out.println("Feature A1");
|
||||
}
|
||||
}
|
||||
```
|
@ -1,79 +0,0 @@
|
||||
package cn.whaifree.interview.PA;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author whai文海
|
||||
* @Date 2024/10/30 17:38
|
||||
* @注释
|
||||
*/
|
||||
public class P1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
// 注意 hasNext 和 hasNextLine 的区别
|
||||
while (in.hasNextInt()) { // 注意 while 处理多个 case
|
||||
int n = in.nextInt();
|
||||
int m = in.nextInt();
|
||||
|
||||
/**
|
||||
* 0 1 2
|
||||
* 0 0 0 0
|
||||
* 1 1 1 1
|
||||
* 2 1 2 3
|
||||
* 3 1 3 6
|
||||
*/
|
||||
int[] dp = new int[m + 1];
|
||||
dp[0] = 1;
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 1; j <= m; j++) {
|
||||
dp[j] = dp[j] + dp[j - 1];
|
||||
}
|
||||
}
|
||||
System.out.println(dp[m]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
class p2{
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String str = scanner.next();
|
||||
|
||||
int res = 0;
|
||||
for (int right = 0; right <= str.length(); right++) {
|
||||
for (int left = 0; left < right; left++) {
|
||||
String leftStr = str.substring(0, left);
|
||||
String rightStr = str.substring(right, str.length());
|
||||
String concat = leftStr + rightStr;
|
||||
if (!concat.isEmpty() && huiwen(concat)) {
|
||||
System.out.println(concat);
|
||||
res++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(res);
|
||||
|
||||
}
|
||||
|
||||
public static boolean huiwen(String str){
|
||||
int left = 0;
|
||||
int right = str.length() - 1;
|
||||
while (left < right) {
|
||||
if (str.charAt(left) != str.charAt(right)) {
|
||||
return false;
|
||||
}
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package cn.whaifree.interview.jr;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author whai文海
|
||||
* @Date 2024/10/22 12:11
|
||||
* @注释
|
||||
*/
|
||||
public class p1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
|
||||
int people = in.nextInt();
|
||||
int gzNum = in.nextInt();
|
||||
int[] nums = new int[people];
|
||||
for (int i = 0; i < people; i++) {
|
||||
nums[i] = in.nextInt();
|
||||
}
|
||||
|
||||
int[] gzNums = new int[gzNum];
|
||||
|
||||
for (int i = 0; i < nums.length; i++) {
|
||||
int want = nums[i];
|
||||
gzNums[want - 1]++;
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
for (int num : gzNums) {
|
||||
int needSum = num / 2;
|
||||
if (num % 2 == 1) {
|
||||
res += (needSum + 1);
|
||||
} else {
|
||||
res += (needSum);
|
||||
}
|
||||
}
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class p2{
|
||||
public static void main(String[] args) {
|
||||
Scanner in = new Scanner(System.in);
|
||||
// 注意 hasNext 和 hasNextLine 的区别
|
||||
int v0 = in.nextInt(); // 初始速度
|
||||
int x = in.nextInt(); // v=v0+t*x
|
||||
int y = in.nextInt(); // 总里程
|
||||
// t1 = y / v = y / (v0+t*x)
|
||||
// t = 2 / (t) t
|
||||
|
||||
// 速度t 2 2/t=2.8284271 t = 2/更好8 = 根号2/2
|
||||
double t = Math.sqrt(2) / 2;
|
||||
System.out.println(y / (v0 + t * x));
|
||||
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ import java.util.Arrays;
|
||||
*
|
||||
* 如果你已经实现 O(n) 时间复杂度的解法, 请尝试设计一个 O(n log(n)) 时间复杂度的解法。
|
||||
*/
|
||||
public class LeetCode209_2 {
|
||||
public class LeetCode209 {
|
||||
|
||||
/**
|
||||
* 暴力求解,会超时
|
@ -13,7 +13,7 @@ public class LeetCode115 {
|
||||
public void test()
|
||||
{
|
||||
Solution solution = new Solution();
|
||||
System.out.println(solution.numDistinct("babgbag", "bag"));
|
||||
System.out.println(solution.numDistinct("rabbbit", "rabbit"));
|
||||
}
|
||||
|
||||
class Solution {
|
@ -9,7 +9,7 @@ import org.junit.Test;
|
||||
* @注释
|
||||
*/
|
||||
|
||||
public class LeetCode718_2 {
|
||||
public class LeetCode718 {
|
||||
@Test
|
||||
public void test()
|
||||
{
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user