531. Lonely Pixel I
来源:互联网 发布:外国人丁丁体验知乎 编辑:程序博客网 时间:2024/06/07 00:49
Given a picture consisting of black and white pixels, find the number of black lonely pixels.
The picture is represented by a 2D char array consisting of 'B' and 'W', which means black and white pixels respectively.
A black lonely pixel is character 'B' that located at a specific position where the same row and same column don't have any other black pixels.
Example:
Input: [['W', 'W', 'B'], ['W', 'B', 'W'], ['B', 'W', 'W']]Output: 3Explanation: All the three 'B's are black lonely pixels.
Note:
- The range of width and height of the input 2D array is [1,500].
public class Solution { public int findLonelyPixel(char[][] picture) { int m = picture.length, n = picture[0].length; int[] row = new int[m]; int[] col = new int[n]; for (int i = 0; i < m; i ++) { for (int j = 0; j < n; j ++) { if (picture[i][j] == 'B') { row[i] ++; col[j] ++; } } } int count = 0; for (int i = 0; i < m; i ++) { for (int j = 0; j < n; j ++) { if (picture[i][j] == 'B' && row[i] == 1 && col[j] == 1) { count ++; } } } return count; }}
阅读全文
0 0
- 531. Lonely Pixel I
- 531. Lonely Pixel I ----Leetcode
- [LeetCode]531. Lonely Pixel I
- [Leetcode] 531. Lonely Pixel I 解题报告
- 532. K-diff Pairs in an Array\531. Lonely Pixel I
- 533. Lonely Pixel II
- Leetcode 533 Lonely Pixel II
- [Leetcode] 533. Lonely Pixel II 解题报告
- I am lonely
- lonely
- lonely
- I just want to say, I was a lonely programmer
- Lonely lonely lonely...
- I wondered lonely as a cloud我似行云独自游
- pixel
- Pixel
- [Music]Lonely
- Lonely Christmas!
- 第一笔
- ITSS服务管理体系建立流程(四个阶段)附:广东软件行业协会ITSS评估
- 博文重读,意味深长
- Java学习笔记系列03
- 数据库Datetime,Timestamp写入为0000-00-00 00:00:00
- 531. Lonely Pixel I
- 点击手机自带的返回键两次退出程序
- 盾牌合体效果
- win7下个人无线网络的建设以及用户文件的共享
- AxonFramework测试
- Java学习笔记系列04
- 记录昨天20170614
- Synchronized wait() notifyAll/notify 另一个方法(合作关系)
- 无需ROOT就能拿ANR日志