[Leetcode] COM/problems/surrounded-regions/

Source: Internet
Author: User
DFS stack overflow, BFs timeout, no overflow with DFS non-recursion, write one week before and after
Class node {int I; Int J; Public node (INT I1, int J1) {I = I1; j = J1 ;}} public class solution {public void solve (char [] [] Board) {int len1 = board. length; If (len1 <= 0) return; int len2 = Board [0]. length; If (len1 <= 2 | len2 <= 2) return; For (INT I = 0; I <len1; I ++) {If (Board [I] [0] = 'O') DFS (board, I, 0); If (Board [I] [len2-1] = 'O ') DFS (board, I, len2-1);} For (INT I = 0; I <len2; I ++) {If (Board [0] [I] = 'O') DFS (board, 0, I); If (Board [len1-1] [I] = 'O ') DFS (board, len1-1, I) ;}for (INT I = 0; I <len1; I ++) {for (Int J = 0; j <len2; j ++) {If (Board [I] [J] = 'H') Board [I] [J] = 'O '; else Board [I] [J] = 'X' ;}} public Boolean is (int I, Int J, int len1, int len2) {if (I >=0 & I <len1 & J> = 0 & J <len2) return true; return false ;} public void DFS (char B [] [], int I, Int J) {int len1 = B. length; int len2 = B [0]. length; stack <node> S = new stack <node> (); B [I] [J] = 'H'; S. push (new node (I, j ));}}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.