@@ -31,44 +31,23 @@ Use a HashMap (m) to store the frequency of each number in the array.
31
31
- - - - 3* n + 2 = 3* (n) + 2* (1) -> n+1 operations
32
32
- Return Result :
33
33
- - Return the total number of operations needed to make all numbers in the array divisible by 3.
34
- =======
35
- ## Today's 03-01-24 [ Problem Link] ( https://leetcode.com/problems/number-of-laser-beams-in-a-bank/description/?envType=daily-question&envId=2024-01-03 )
36
-
37
- # Intuition
38
- <!-- Describe your first thoughts on how to solve this problem. -->
39
- Basic multiplication.
40
- # Approach
41
- <!-- Describe your approach to solving the problem. -->
42
- - I kept track of number of '1' in a row
43
- - Now iterated over every row of array
44
- - - counted the number of '1' in current row
45
- - - number of beams will the product of current number of device and previous number of devices
46
- - - added the product to answer
47
- - - now, the current one will become the previous one to next row
48
- >>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
49
34
---
50
35
Have a look at the code , still have any confusion then please let me know in the comments
51
36
Keep Solving.:)
52
37
53
38
# Complexity
54
39
- Time complexity : $$ O(l) $$
55
40
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
56
- <<<<<<< HEAD
57
41
58
42
- Space complexity : $$ O(u) $$
59
43
60
44
$$ l $$ : size of array
61
45
$$ u $$ : number of unique letters in array
62
- =======
63
- $$ l $$ : length of array
64
- - Space complexity : $$ O(1) $$
65
- >>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
66
46
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
67
47
68
48
# Code
69
49
```
70
50
class Solution {
71
- <<<<<<< HEAD
72
51
public int minOperations(int[] nums) {
73
52
boolean haveone = false;
74
53
HashMap<Integer, Integer> m = new HashMap<>();
@@ -95,20 +74,6 @@ class Solution {
95
74
}
96
75
}
97
76
return operations;
98
- =======
99
- public int numberOfBeams(String[] bank) {
100
- int jawab = 0; // to store answer
101
- int picheek = 0; // to store number of '1' in previous state
102
-
103
- for( String r : bank){
104
- int ek = (int) r.chars().filter( g -> g == '1').count(); // counting the number of '1' in current row
105
- if( ek != 0){ // number of beams will the product of current number of device and previous number of devices
106
- jawab += picheek*ek; // adding the product to answer
107
- picheek = ek; // now, the current one will become the previous one to next row
108
- }
109
- }
110
- return jawab;
111
- >>>>>>> 8326dfdfc4354991bd3c7f23df8fcaa854307652
112
77
}
113
78
}
114
- ```
79
+ ```
0 commit comments