You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classSolution {
public:
vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
int n = candies.size();
vector<bool> result(n, false);
int max = 0;
for (int i = 0; i < n; i++) {
if (max < candies[i]) {
max = candies[i];
}
}
for (int i = 0; i < n; i++) {
if (max <= candies[i] + extraCandies) {
result[i] = true;
}
}
return result;
}
};
간단한 최대값 문제
더 쉽게 푸는 방법에 대한 메서드가 있음
classSolution {
public:
vector<bool> kidsWithCandies(vector<int>& candies, int extraCandies) {
int maxCandies = *max_element(candies.begin(), candies.end()); // 한 줄로 최대값 계산
vector<bool> result;
for (int candy : candies) {
result.push_back(candy + extraCandies >= maxCandies); // 결과 바로 추가
}
return result;
}
};
The text was updated successfully, but these errors were encountered:
더 쉽게 푸는 방법에 대한 메서드가 있음
The text was updated successfully, but these errors were encountered: