From ecf2f98b858f246d45b7e4da2f307955278e9f69 Mon Sep 17 00:00:00 2001 From: Cool <747682928@qq.com> Date: Wed, 11 Sep 2024 23:53:17 +0800 Subject: [PATCH] =?UTF-8?q?2024/9/11=20LeetCode=20Hot100=20backtracking?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E4=B8=8A=E5=91=A8=E5=91=A8=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cool/hot100/backtracking/Num79.java | 54 +++++++++++++++++++ src/main/java/com/cool/week414/Problem1.java | 36 +++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/main/java/com/cool/hot100/backtracking/Num79.java create mode 100644 src/main/java/com/cool/week414/Problem1.java diff --git a/src/main/java/com/cool/hot100/backtracking/Num79.java b/src/main/java/com/cool/hot100/backtracking/Num79.java new file mode 100644 index 0000000..a6c483e --- /dev/null +++ b/src/main/java/com/cool/hot100/backtracking/Num79.java @@ -0,0 +1,54 @@ +package com.cool.hot100.backtracking; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/11/21:21 + * DayNumber 1 + * Hard 2 + * Level 4 + */ +public class Num79 { + + public boolean exist(char[][] board, String word) { + if (board.length < 1) { + return false; + } + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + if (board[i][j] == word.charAt(0)) { + if (dfs(board, word, i, j, 0)) { + return true; + } + } + + } + } + return false; + } + + private boolean dfs(char[][] chars, String word, int x, int y, int index) { + if (index == word.length()) { + return true; + } + if (x < 0 || x >= chars.length || y < 0 || y >= chars[0].length) { + return false; + } + if (chars[x][y] == '1') { + return false; + } + boolean is = false; + if (word.charAt(index) == chars[x][y]) { + char temp = chars[x][y]; + chars[x][y] = '1'; + is =dfs(chars, word, x + 1, y, index + 1) || dfs(chars, word, x, y + 1, index + 1) + || dfs(chars, word, x - 1, y, index + 1) || dfs(chars, word, x, y - 1, index + 1); + chars[x][y] = temp; + return is; + } else { + return false; + } + } + +} diff --git a/src/main/java/com/cool/week414/Problem1.java b/src/main/java/com/cool/week414/Problem1.java new file mode 100644 index 0000000..f91617b --- /dev/null +++ b/src/main/java/com/cool/week414/Problem1.java @@ -0,0 +1,36 @@ +package com.cool.week414; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/08/11:28 + * ProblemNumber + */ +public class Problem1 { + public String convertDateToBinary(String date) { + String[] dates=date.split("-"); + String res=""; + for(int i=0;i