开发者

least generator I need, a leetcode-like programming problem [closed]

开发者 https://www.devze.com 2022-12-07 21:43 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post.
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 11 hours ago.

Improve this question

Suppose each machine needs at least one generator next to it. Write a function to print out the least generators I need given an input row.

At first I think this question is easy to solve if I write a lot of "If-else" clauses. But I cannot find out how to think this question in a structured way.


Input1: row = "MIIM". Here "M" refers machine, "I" refers interval. Each interval can contain one generator.

Output1: 2

Two generators needed for two machines.


Inp开发者_运维技巧ut2: row = "IMIMI".

Output2: 1

Two machines can share one generator.

0

精彩评论

暂无评论...
验证码 换一张
取 消