|
| 1 | +#include <iostream> |
| 2 | +using namespace std; |
| 3 | + |
| 4 | +class Solution { |
| 5 | + public: |
| 6 | + bool canMakeSquare(vector<vector<char>>& grid) { |
| 7 | + /** |
| 8 | + * B B B . B w b |
| 9 | + * w w w . w b w |
| 10 | + * b b b b w b b |
| 11 | + */ |
| 12 | + int cnt_w = 0; |
| 13 | + for (int i = 0; i < 2; i++) { |
| 14 | + for (int j = 0; j < 2; j++) { |
| 15 | + if (grid[i][j] == 'W') { |
| 16 | + cnt_w ++; |
| 17 | + } |
| 18 | + } |
| 19 | + } |
| 20 | + if (cnt_w != 2) return true; |
| 21 | + cnt_w = 0; |
| 22 | + |
| 23 | + for (int i = 0; i < 2; i++) { |
| 24 | + for (int j = 1; j < 3; j++) { |
| 25 | + if (grid[i][j] == 'W') { |
| 26 | + cnt_w ++; |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + if (cnt_w != 2) return true; |
| 31 | + cnt_w = 0; |
| 32 | + |
| 33 | + for (int i = 1; i < 3; i++) { |
| 34 | + for (int j = 0; j < 2; j++) { |
| 35 | + if (grid[i][j] == 'W') { |
| 36 | + cnt_w ++; |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + if (cnt_w != 2) return true; |
| 41 | + cnt_w = 0; |
| 42 | + |
| 43 | + for (int i = 1; i < 3; i++) { |
| 44 | + for (int j = 1; j < 3; j++) { |
| 45 | + if (grid[i][j] == 'W') { |
| 46 | + cnt_w ++; |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + if (cnt_w != 2) return true; |
| 51 | + |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @brief 138th weekly Q1: key of numbers [E] |
| 57 | + * basic number ops, very easy |
| 58 | + * |
| 59 | + * @param num1 num2 num3 |
| 60 | + * @return int |
| 61 | + */ |
| 62 | + int generateKey(int num1, int num2, int num3) { |
| 63 | + int ans = 0; |
| 64 | + int flag = 1; |
| 65 | + while (num1 >= 10 || num2 >= 10 || num3 >= 10) { |
| 66 | + int n1 = num1 % 10; |
| 67 | + int n2 = num2 % 10; |
| 68 | + int n3 = num3 % 10; |
| 69 | + num1 /= 10; |
| 70 | + num2 /= 10; |
| 71 | + num3 /= 10; |
| 72 | + ans = ans + flag * min(min(n1, n2), n3); |
| 73 | + flag *= 10; |
| 74 | + } |
| 75 | + ans = ans + flag * min(min(num1, num2), num3); |
| 76 | + return ans; |
| 77 | + } |
| 78 | + |
| 79 | +}; |
0 commit comments