zoukankan      html  css  js  c++  java
  • 79. Word Search

    class Solution {
        public boolean exist(char[][] board, String word) {
            if(board.length==0||board[0].length==0)
                return false;
            boolean[][] used=new boolean[board.length][board[0].length];
            for(int i=0;i<board.length;i++)
                for(int j=0;j<board[0].length;j++)
                    if(search(i, j, board, used, word))
                        return true;
            return false;
        }
        private boolean search(int i, int j, char[][] board, boolean[][] used, String word){
            if(word.length()==0)
                return true;
            if(i<0||i>=board.length||j<0||j>=board[0].length||used[i][j]==true||word.charAt(0)!=board[i][j])
                return false;
            used[i][j]=true;
            boolean res=search(i-1,j,board,used,word.substring(1))||search(i+1,j,board,used,word.substring(1))
                ||search(i,j-1,board,used,word.substring(1))||search(i,j+1,board,used,word.substring(1));
            used[i][j]=false;
            return res;
        }
    }
  • 相关阅读:
    指定pdf的格式
    iptables 防火墙
    jumpserver2
    jquery UI
    python 自动化审计
    Jumpserver
    认识二进制安全与漏洞攻防技术 (Windows平台)
    将这段美化的css代码
    pycharm
    android Tips
  • 原文地址:https://www.cnblogs.com/asuran/p/7599829.html
Copyright © 2011-2022 走看看