Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpinningDiskDevice
- {
- private int lastInput;
- private int segmentLength;
- /**
- Constructs a spinning disk device.
- */
- public SpinningDiskDevice()
- {
- lastInput = 0;
- segmentLength = 0;
- }
- /**
- Processes a new input
- @param input 0 or 1
- */
- public void add(int input)
- {
- if(input == lastInput)
- {
- segmentLength++;
- }
- else
- {
- lastInput = input;
- segmentLength = 1;
- }
- }
- /**
- Gets the length of the current segment.
- */
- public int getSegmentLength()
- {
- return segmentLength;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement