码迷,mamicode.com
首页 > 其他好文 > 详细

302. Smallest Rectangle Enclosing Black Pixels

时间:2016-07-04 06:35:58      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

    /*
     * 302. Smallest Rectangle Enclosing Black Pixels
     * 2016-7-3 by Mingyang
     * 不看
     */
     int l,r,u,d;  
        public int minArea(char[][] image, int x, int y) {  
            //input check  
            u=x;  
            d=x;  
            l=y;  
            r=y;  
            int m = image.length-1;  
            int n = image[0].length-1;  
            boolean[][] visited = new boolean[m+1][n+1];  
            search(image, visited, x, y, m, n);  
            return (r-l+1) * (d-u+1);  
        }  
        private void search(char[][] image, boolean[][] visited, int x, int y, int m, int n) {  
            if(x<0 || x>m || y<0 || y>n || image[x][y]!=‘1‘ || visited[x][y]) return;  
            visited[x][y] = true;  
            if(x<u) u=x;  
            else if(x>d)d=x;  
            if(y<l) l=y;  
            else if(y>r) r=y;  
            search(image, visited, x-1, y, m, n);  
            search(image, visited, x, y-1, m, n);  
            search(image, visited, x+1, y, m, n);  
            search(image, visited, x, y+1, m, n);  
        }  

 

302. Smallest Rectangle Enclosing Black Pixels

标签:

原文地址:http://www.cnblogs.com/zmyvszk/p/5639333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!