首页 > 学院 > 开发设计 > 正文

531. Lonely Pixel I ----Leetcode

2019-11-06 06:51:28
字体:
来源:转载
供稿:网友
public class Solution {    public int findLonelyPixel(char[][] picture) {        int count=0;        HashMap<Integer,Integer> row =new HashMap<>();        HashMap<Integer,Integer> column =new HashMap<>();        for(int i=0;i<picture.length;i++){            for(int j=0;j<picture[0].length;j++){                if(picture[i][j]=='B'){                    if(row.containsKey(i)){                        row.put(i,row.get(i)+1);                    }else{                        row.put(i,1);                    }                    if(column.containsKey(j)){                        column.put(j,column.get(j)+1);                    }else{                        column.put(j,1);                     }                }            }        }        for(int i=0;i<picture.length;i++){            for(int j=0;j<picture[0].length;j++){                if(picture[i][j]=='B'&&row.containsKey(i)&&row.get(i)==1&&column.containsKey(j)&&column.get(j)==1){                    count++;                }            }        }        return count;    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表