From dac9cdc8c6a8c7b87f41d8b8178c913a4c1b2b29 Mon Sep 17 00:00:00 2001 From: YunMao Date: Sat, 26 Dec 2020 21:06:46 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=9B=E6=89=A30085?= =?UTF-8?q?=E3=80=810455?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + yunmao/README.md | 14 +++++++++ yunmao/src/L0085.java | 67 +++++++++++++++++++++++++++++++++++++++++++ yunmao/src/L0455.java | 35 ++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 .gitignore create mode 100644 yunmao/README.md create mode 100644 yunmao/src/L0085.java create mode 100644 yunmao/src/L0455.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..88dbff1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vs/ diff --git a/yunmao/README.md b/yunmao/README.md new file mode 100644 index 0000000..d8b8a20 --- /dev/null +++ b/yunmao/README.md @@ -0,0 +1,14 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +## Dependency Management + +The `JAVA DEPENDENCIES` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-pack/blob/master/release-notes/v0.9.0.md#work-with-jar-files-directly). diff --git a/yunmao/src/L0085.java b/yunmao/src/L0085.java new file mode 100644 index 0000000..c153a2d --- /dev/null +++ b/yunmao/src/L0085.java @@ -0,0 +1,67 @@ +public class L0085 { + public static void main(String[] args) throws Exception { + char[][] g = {{'0','0','0','0','0','0','1'},{'0','0','0','0','1','1','1'},{'1','1','1','1','1','1','1'},{'0','0','0','1','1','1','1'}}; + System.out.print(maximalRectangle(g)); + } + + public static int maximalRectangle(char[][] matrix) { + int x, y; + int i,j; + int row = matrix.length; + int col; + if (row == 0){ + return 0; + } + else{ + col = matrix[0].length; + } + int sum = 0; + for (x = 0; x < row; x++) { + for (y = 0; y < col; y++) { + if (matrix[x][y] == '1') { + i = x; + j = y; + int a = 1; + int b = 1; + int k; + int sum2 = 0; + while (i < row) { + if (matrix[i][y] == '1') { //竖着往下遍历 + i++; + a = i - x; + j = y + 1; + int temp = j; + while (j < col) { + for (k = x; k < i; k++){ + if (matrix[k][j] == '0'){ //遇到横的为零 + temp = j; + b = temp - y; + j = col; + break; + } + else{ + temp = j + 1; + } + } + j++; + } + b = temp - y; + if (a*b > sum2){ + sum2 = a*b; + } + + } + else{ + break; + } + } + if (sum2 > sum){ + sum = sum2; + } + } + } + } + return sum; + + } +} diff --git a/yunmao/src/L0455.java b/yunmao/src/L0455.java new file mode 100644 index 0000000..e1a23e0 --- /dev/null +++ b/yunmao/src/L0455.java @@ -0,0 +1,35 @@ +import java.util.Arrays; + +public class L0455 { + public static void main(String[] args) throws Exception { + int[] g = { 10, 9, 8, 7 }; + int[] s = { 5, 6, 7, 8, 6 }; + System.out.print(findContentChildren(g, s)); + } + + public static int findContentChildren(int[] g, int[] s) { + int i, j; + int g_num = g.length; + int s_num = s.length; + Arrays.sort(g); + Arrays.sort(s); + int sum = 0; + int a = 0; + int position = 0; + for (i = 0; i < s_num; i++) { + for (j = position; j < g_num; j++) { + a += 1; + if (s[i] >= g[j]) { + // System.out.println(s[i]); + // System.out.println(g[j]); + sum = sum + 1; + position = j + 1; + j = g_num; + } + + } + } + // System.out.println(a); + return sum; + } +}