Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 1894. Find the Student that Will Replace the Chalk

Posted on 2021-06-13 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
class Solution {
public:
int chalkReplacer(vector<int>& chalk, int k) {
long long s = 0;
for (int c : chalk) s += c;
int t = k % s, i = 0;
while (t >= chalk[i]) t -= chalk[i++];
return i;
}
};
# Greedy# Array
LeetCode 1895. Largest Magic Square
LeetCode 1897. Redistribute Characters to Make All Strings Equal
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%