当前位置:网站首页>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;
}
}
边栏推荐
- [ssrf-01] principle and utilization examples of server-side Request Forgery vulnerability
- [technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
- [flask] response, session and message flashing
- Superfluid_ HQ hacked analysis
- [Yu Yue education] Liaoning Vocational College of Architecture Web server application development reference
- 一图看懂!为什么学校教了你Coding但还是不会的原因...
- 037 PHP login, registration, message, personal Center Design
- SPIR-V初窺
- 剑指 Offer 38. 字符串的排列
- Ordinary people end up in Global trade, and a new round of structural opportunities emerge
猜你喜欢
Basic process and testing idea of interface automation
MUX VLAN configuration
1. Introduction to basic functions of power query
Folio.ink 免费、快速、易用的图片分享工具
Initialize MySQL database when docker container starts
Basic operations of database and table ----- set the fields of the table to be automatically added
leetcode刷题_平方数之和
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
False breakthroughs in the trend of London Silver
[机缘参悟-39]:鬼谷子-第五飞箝篇 - 警示之二:赞美的六种类型,谨防享受赞美快感如同鱼儿享受诱饵。
随机推荐
CocoaPods could not find compatible versions for pod 'Firebase/CoreOnly'
D22:indeterminate equation (indefinite equation, translation + problem solution)
What is weak reference? What are the weak reference data types in ES6? What are weak references in JS?
Unreal browser plug-in
Loop structure of program (for loop)
A Cooperative Approach to Particle Swarm Optimization
Folio.ink 免费、快速、易用的图片分享工具
正则表达式:示例(1)
Redis-列表
Crawler request module
037 PHP login, registration, message, personal Center Design
Poj2315 football games
[flask] static file and template rendering
Maya hollowed out modeling
You are using pip version 21.1.1; however, version 22.0.3 is available. You should consider upgradin
A picture to understand! Why did the school teach you coding but still not
[technology development -28]: overview of information and communication network, new technology forms, high-quality development of information and communication industry
Leetcode 剑指 Offer 59 - II. 队列的最大值
ClickOnce 不支持请求执行级别“requireAdministrator”
1. Introduction to basic functions of power query