File tree Expand file tree Collapse file tree 4 files changed +13
-13
lines changed
solution/3400-3499/3450.Maximum Students on a Single Bench Expand file tree Collapse file tree 4 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ public:
156
156
}
157
157
int ans = 0;
158
158
for (const auto& s : d) {
159
- ans = max(ans, (int)s.second.size());
159
+ ans = max(ans, (int) s.second.size());
160
160
}
161
161
return ans;
162
162
}
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ public:
154
154
}
155
155
int ans = 0;
156
156
for (const auto& s : d) {
157
- ans = max(ans, (int)s.second.size());
157
+ ans = max(ans, (int) s.second.size());
158
158
}
159
159
return ans;
160
160
}
Original file line number Diff line number Diff line change @@ -3,11 +3,12 @@ class Solution {
3
3
int maxStudentsOnBench (vector<vector<int >>& students) {
4
4
unordered_map<int , unordered_set<int >> d;
5
5
for (const auto & e : students) {
6
- d[e[0 ]].insert (e[1 ]);
6
+ int studentId = e[0 ], benchId = e[1 ];
7
+ d[benchId].insert (studentId);
7
8
}
8
9
int ans = 0 ;
9
- for (auto & [_, s] : d) {
10
- ans = max (ans, (int ) s.size ());
10
+ for (const auto & s : d) {
11
+ ans = max (ans, (int ) s.second . size ());
11
12
}
12
13
return ans;
13
14
}
Original file line number Diff line number Diff line change 1
1
class Solution {
2
- public :
3
- int maxStudentsOnBench (vector <vector <int >>& students ) {
4
- unordered_map <int , unordered_set <int >> d ;
5
- for (const auto & e : students ) {
2
+ public int maxStudentsOnBench (int [][] students ) {
3
+ Map <Integer , Set <Integer >> d = new HashMap <>();
4
+ for (var e : students ) {
6
5
int studentId = e [0 ], benchId = e [1 ];
7
- d [ benchId ]. insert (studentId );
6
+ d . computeIfAbsent ( benchId , k -> new HashSet <>()). add (studentId );
8
7
}
9
8
int ans = 0 ;
10
- for (const auto & s : d ) {
11
- ans = max (ans , ( int ) s . second .size ());
9
+ for (var s : d . values () ) {
10
+ ans = Math . max (ans , s .size ());
12
11
}
13
12
return ans ;
14
13
}
15
- };
14
+ }
You can’t perform that action at this time.
0 commit comments