Thursday, March 27, 2014

Topcoder SRM 612 DIV 2 L1 LeftAndRightHandedDiv2

// Topcoder SRM 612 DIV 2 L1 LeftAndRightHandedDiv2
import java.util.*;
import java.math.*;

public class LeftAndRightHandedDiv2 {
public static void main(String[] args) {
LeftAndRightHandedDiv2 obj = new LeftAndRightHandedDiv2();
System.out
.println(
obj.count(
"LR"
));
}

public int count(String S) {
int c = 0;
for (int i = 1; i < S.length(); i++) {
if (S.charAt(i) == 'L' && S.charAt(i - 1) == 'R')
c++;
}
return c;
}
}

No comments:

Post a Comment