【leetcode】79. Word Search

LeetCode刷题:79. Word Search — JAVA DFS算法 LeetCode刷题:79. Word Search 原题链接:https://leetcode.com/problems/word-search/ Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially... 阅读详情

简单的dfs

/**
 *  @author         johnsondu
 *  @time           20:01 8th Oct 2015
 *  @type           dfs
 *  @url            https://leetcode.com/problems/word-search/
 *  @status         Accepted
 */

class Solution {
public:
    void dfs(int x, int y, int idx, int len, int row, int col, vector<vector<bool>> &mark, bool &flag, vector<vector<char>>& board, string word)
    {
        if(flag) return;
        if(word[idx] != board[x][y]) return;
        if(idx == len - 1) {
            flag = true;
            return;
        }
        
        int dir[][2] = {1, 0, -1, 0, 0, 1, 0, -1};
        for(int k = 0; k < 4; k ++) {
            int tx = x + dir[k][0];
            int ty = y + dir[k][1];
            if(tx >= row || ty >= col || tx < 0 || ty < 0) continue;
            if(mark[tx][ty]) continue;
            mark[tx][ty] = true;
            dfs(tx, ty, idx + 1, len, row, col, mark, flag, board, word);
            mark[tx][ty] = false;
        }
    
    }
    
    bool exist(vector<vector<char>>& board, string word) {
        if(board.size() == 0) return false;
        if(word.size() == 0) return true;
        int row = board.size();
        int col = board[0].size();
        vector<vector<bool>> mark(board.size(), vector<bool>(board[0].size(), false));
        bool flag = false;
        int len = word.size();
        for(int i = 0; i < row; i ++) {
            for(int j = 0; j < col; j ++) {
                if(board[i][j] == word[0]) {
                    mark[i][j] = true;
                    dfs(i, j, 0, len, row, col, mark, flag, board, word);
                    mark[i][j] = false;
                    if(flag) return flag;
                }
            }
        }
        return flag;
    }
};


【Allegro学习笔记】常规标贴封装创建-0402封装创建实例 摘要 本文主要介绍如何使用Allegro制作表面贴装封装。 所使用的软件 使用Allegro制作常规贴片封装主要使用的软件有Pad Designer和Allegro 1 0402类封装制作 1.1 0402类封装焊盘分析 0402封装尺寸图如图1... 阅读详情

相关推荐

保姆级教程:用C++逆向解析通达信shm.tnf文件(附完整代码与偏移量详解)

本文提供了一份详细的C++逆向工程教程,指导开发者如何解析通达信的shm.tnf文件。通过分析文件结构、定位关键字段并实现完整解析流程,帮助量化交易开发者高效获取沪市股票数据。教程包含完整代码示例和偏移量详解,适合金融数据本地化处理需求。

weixin_27945229的博客 520

LeetCode 79 Word Search (python)

目录LeetCode 79 Word Search (python)分析find(i, j, word)Code pythonCode C++欢迎一起来参与leetcode刷题项目 LeetCode 79 Word Search (python) 分析 这题是给我们一个由字符组成的二维列表结构,叫做board,我们要做的就是判断这个board里是否包含特定的某个字符串word。 值得注意的是bo...

漂漂飘的博客 644

火山引擎实时对话AI实战:5分钟搞定WebRTC+大模型+ASR/TTS全链路集成

本文详细介绍了如何利用火山引擎的实时对话AI解决方案,快速集成WebRTC、大模型、ASR和TTS服务,构建低延迟、高保真的实时语音对话应用。通过实战代码示例,从环境准备、音频流管理到全链路串联与性能优化,为开发者提供了一套端到端的集成指南,适用于智能客服、在线教育等互动场景。

weixin_29051245的博客 1126

LeetCode 79. Word Search 题解

本题是深度优先搜索的经典应用问题,主要考察对 DFS 算法的理解和使用。通过使用 DFS,我们可以遍历网格中的每个单元格,尝试匹配单词的每个字符。DFS 的核心思想是:从网格中的每个单元格开始,递归地搜索其相邻的单元格,检查是否能够匹配单词的所有字符。在搜索过程中,需要标记已访问的单元格,避免重复使用。这种方法不仅适用于单词搜索问题,还可以应用于许多其他需要遍历二维网格的问题,例如岛屿数量、最大面积岛屿等。掌握 DFS 的使用,对于解决这类问题非常重要。

cannonjinx的博客 4612

【吐血整理-历时两个月,长达万字】FDTD Solutions学习笔记

原教学视频来自于Ansys-Lumerical官方的FDTD100,所看视频来自B站大佬UP主 【Nestor_呐等】 的幸苦翻译,本文内容粘贴自我个人在学习FDTD100时,通过字幕和一些个人理解总结的一份word。整理不易,强烈建议收藏!...

weixin_45719141的博客 10万+

别再对着数据手册发愁了!用HFSS 2023 R2搞定ESP32-C3板载天线的阻抗匹配

本文详细介绍了如何利用HFSS 2023 R2进行ESP32-C3板载天线的阻抗匹配优化,解决实际PCB设计中常见的性能偏差问题。通过智能模型导入、科学参数扫描和量化优化流程,显著提升天线性能,适用于WIFI和蓝牙应用场景。

weixin_42523543的博客 447

Leetcode 79. Word Search 要真正理解回溯的写法!

Leetcode 79. Word Search  public class Solution { public static void main(String[] args){ char[][] board = {{'A','B','C','E'},{'S','F','E','S'},{'A','D','E','E'}}; Solution s = new Solut

独钓寒江雪 1356

树莓派4B系统安装及SSH远程控制(简单易操作)

​自从2022年4月树莓派官网更新了RaspberryPiImager版本v1.7.2后,便不再支持自行建立ssh文件,并用默认用户名pi和密码raspberry的方式进行远程控制(亲测不行,输密码时一直access denied)。但是该版本软件提供了烧录系统前设置ssh用户及密码功能。本文记录了系统安装和SSH远程操作步骤。........................

机械人的代码路 5789

【LeetCode】解题79:Word Search

LeetCode解题 79:Word Search Problem 79: Word Search [Medium]解题思路Solution (Java)修改过程 Problem 79: Word Search [Medium] Given a 2D board and a word, find if the word exists in the grid. The word can be con...

Fayedily的博客 328

蓝牙Mesh协议一基本概念

前言 蓝牙SIG联盟在2017年发布了蓝牙Mesh1.0的协议规格,基于低功耗广播包来实现的多对多的通信技术,Mesh协议建立在BLE的物理层和链路层上,所以也可以和BLE的蓝牙进行通信 本章主要介绍蓝牙Mesh的基本概念和协议中的层级结构,也是参考网上的资料,如有异议,欢迎留言指正 基本概念 广播和洪泛 蓝牙Mesh技术是基于BLE的广播报文来实现的,是一种洪泛的消息传输机制,Mesh网络的节点间通过3个广播信道进行通信。当蓝牙Mesh网络中的节点收到消息后会转发这条消息,大大增加了网络的覆盖范围;但

9735

linux下wayland协议修改键盘映射

linux下wayland协议,修改键盘映射,实验环境是Ubuntu24,其他wayland协议窗口应该也是可以的。

qq_15027967的博客 1068

LeetCode 79. Word Search

LeetCode 79. Word Search (Medium) 主要知识点:DFS;优先级:5

温迪今天刷题了吗 220

第5.2章 【自动驾驶行业融合定位核心】:手把手详解ESKF(误差卡尔曼滤波)理论公式及代码

自动驾驶定位中的ESKF(误差卡尔曼滤波)技术是解决IMU累积误差的关键,通过分离名义状态与误差状态实现高精度定位。其核心步骤包括:1)名义状态递推(位置/速度/姿态的基础物理计算);2)误差传播建模(雅可比矩阵F量化误差影响);3)协方差更新(评估定位不确定性)。ESKF在GNSS信号丢失(如隧道场景)、无卫星定位(地下车库)等场景发挥重要作用,通过融合多传感器数据维持定位精度。工程实现需解决零偏校准、协方差投影等关键问题,噪声参数需通过数据标定而非随意设置。掌握ESKF原理与实现是自动驾驶定位工程师的核

行知SLAM 702

Leetcode 79. Word Search

问题描述:在图中搜索给定单词,如果存在就返回True否则为False. 题目链接:Leetcode 79. Word Search 思路:dfs搜索,一旦不符合条件就退出,直到符合条件。有矩阵的题目,要么是利用dfs、bfs遍历、要么就是动态规划找出递推条件。考虑遍历去重,visited、边界问题、合理剪枝,一旦达到目的就暂停。 代码如下 class Solution: def ex...

Za七杂⑧ 177

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

LeetCode --- 79. Word Search

题目链接:Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontal

makuiyu的专栏 752

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

LeetCode: 79. Word Search

LeetCode: 79. Word Search 题目描述 Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are t...

杨领well的专栏 1396

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

LeetCode力扣之79. Word Search

Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically nei...

LeeWei 278

79. word search java_【LeetCode】 79. Word Search 单词搜索(Medium)(JAVA)

【LeetCode】 79. Word Search 单词搜索(Medium)(JAVA)题目地址: https://leetcode.com/problems/word-search/题目描述:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from lett...

weixin_33168937的博客 179

LeetCode题解 #79 Word Search

LeetCode题解 #79 Word Search源暗 发布于 9月27日 0评论 1817浏览leetcode 0  0 题目描述Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent ce...

iking83的博客 261

leetcode 79. Word Search 改进版本的dfs算法

leetcode 79. Word Search board[i][j] = '#';采用这种方式进行标记,good idea! public class Solution { public static void main(String[] args){ char[][] board = {{'A','B','C','E'},{'S','F','E','S'},{'A','D','

独钓寒江雪 495

Leetcode 79. Word Search 单词搜索

Leetcode 79. Word Search 单词搜索 标签: Leetcode 题目地址: https://leetcode-cn.com/problems/word-search/ 题目描述 给定一个二维网格和一个单词,找出该单词是否存在于网格中。 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用...

CoderWangSon 324

LeetCode 79(Word Search)java

原题:Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertica

Jassy1994的博客 2493

【DFS + Backtracking】LeetCode 79. Word Search

LeetCode 79. Word Search class Solution { public: bool exist(vector&amp;amp;amp;amp;lt;vector&amp;amp;amp;amp;lt;char&amp;amp;amp;amp;gt;&amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp; board, string word) { int m = board.size();

Allenlzcoder的博客 420

leetcode-79. Word Search

leetcode-79. Word Search题目: 典型的DFS方法,不过这里还要考虑一下不可重复搜索的问题。之前做的时候没注意到。

千念飞羽的专栏 338

LeetCode-79. Word Search [C++][Java]

Given anm x ngrid of charactersboardand a stringword, returntrueifwordexists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter ce

贫道绝缘子的博客 342
上一篇: 【leetcode】34. Search for a Range
下一篇: 【leetcode】78. Subsets
小do在努力
博客等级 码龄16年 58粉丝 161原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值