✅Beats 85||Simple solution||Smooooooth🧈
\n# Intuition\nThe goal is to count the number of beams that can be formed between devices in different rows, considering the following conditions:\n1. A beam c
![image.png](https://assets.leetcode.com/users/images/a99ee9c8-b979-4056-8522-9d9aa2dd3499_1704258316.6214545.png)\n# Intuition\nThe goal is to count the number of beams that can be formed between devices in different rows, considering the following conditions:\n1. A beam can only be formed between devices with \'1\' in adjacent columns.\n2. There must be at least one device with \'1\' in the current row.\n3. There must be at least one device with \'1\' in the previous row.\n\n# Approach\n1. Initialize variables `a`, `b`, `ans`, and `count` to 0.\n2. Iterate through each row of the bank:\n   - For each row, count the number of devices with \'1\' and update the `count`.\n   - If `count` is not equal to 0, update `b = a`, `a = count`, reset `count`, and check if both `a` and `b` are non-zero.\n     - If true, increment `ans` by the product `a * b`.\n     - Reset `b` to 0.\n3. Return the final `ans` as the total number of beams.\n\n# Complexity\n- Time complexity: O(M * N), where M is the number of rows and N is the number of columns in the bank.\n- Space complexity: O(1)\n\n# Code\n```java\nclass Solution {\n    public int numberOfBeams(String[] bank) {\n        int a = 0, b = 0, ans = 0, count = 0;\n        for (int i = 0; i < bank.length; i++) {\n            for (int j = 0; j < bank[i].length(); j++) {\n                if (bank[i].charAt(j) == \'1\')\n                    count++;\n            }\n\n            if (count != 0) {\n                b = a;\n                a = count;\n                count = 0;\n                if (a != 0 && b != 0) {\n                    ans += a * b;\n                    b = 0;\n                }\n            }\n        }\n        return ans;\n    }\n}\n```\n\n# Important concepts\n- Iteration through a 2D array\n- Counting devices with \'1\' in each row\n- Updating variables based on conditions
['Java']