当前位置:网站首页>Sword finger offer 12 Path in matrix
Sword finger offer 12 Path in matrix
2022-07-06 01:39:00 【Yake1965】
The finger of the sword Offer 12. Path in matrix
class Solution {
int m, n, k;
char[][] board;
char[] w;
int[][] dirs = {
{
0, 1}, {
0, -1}, {
1, 0}, {
-1, 0}};
public boolean exist(char[][] board, String word) {
m = board.length;
n = board[0].length;
k = word.length();
this.board = board;
w = word.toCharArray();
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if(board[i][j] == w[0]) {
board[i][j] = '!';
if(f(i, j, 1)) return true;
board[i][j] = w[0];
}
}
}
return false;
}
boolean f(int i, int j, int idx){
if(idx == k) return true;
for(int[] dir : dirs){
int x = i + dir[0];
int y = j + dir[1];
if(x >= 0 && x < m && y >= 0 && y < n && board[x][y] == w[idx]){
board[x][y] = '!';
if(f(x, y, idx + 1)) return true;
board[x][y] = w[idx];
}
}
return false;
}
}
边栏推荐
- Force buckle 9 palindromes
- 【全網最全】 |MySQL EXPLAIN 完全解讀
- Basic process and testing idea of interface automation
- Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
- Yii console method call, Yii console scheduled task
- Superfluid_ HQ hacked analysis
- 阿里测开面试题
- What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
- Unreal browser plug-in
- Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
猜你喜欢

ORA-00030

Huawei converged VLAN principle and configuration

2022年PMP项目管理考试敏捷知识点(8)
![[Jiudu OJ 09] two points to find student information](/img/35/25aac51fa3e08558b1f6e2541762b6.jpg)
[Jiudu OJ 09] two points to find student information
Folio.ink 免费、快速、易用的图片分享工具

Mongodb problem set

How does the crystal oscillator vibrate?

Redis-列表

Kubernetes stateless application expansion and contraction capacity

Leetcode skimming questions_ Verify palindrome string II
随机推荐
2 power view
[solved] how to generate a beautiful static document description page
[le plus complet du réseau] | interprétation complète de MySQL explicite
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
037 PHP login, registration, message, personal Center Design
竞赛题 2022-6-26
[flask] official tutorial -part3: blog blueprint, project installability
Basic process and testing idea of interface automation
Electrical data | IEEE118 (including wind and solar energy)
False breakthroughs in the trend of London Silver
How to see the K-line chart of gold price trend?
3D vision - 4 Getting started with gesture recognition - using mediapipe includes single frame and real time video
Idea sets the default line break for global newly created files
Unity VR resource flash surface in scene
A picture to understand! Why did the school teach you coding but still not
Basic operations of database and table ----- delete data table
Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
leetcode刷题_反转字符串中的元音字母
Paddle框架:PaddleNLP概述【飛槳自然語言處理開發庫】
Yii console method call, Yii console scheduled task