Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. char getMajority(String str)
  2. {
  3. char current = '';
  4. int count=0;
  5. for (char c: str.toCharArray())
  6. {
  7. if (c != current)
  8. count--;
  9. else
  10. count++;
  11.  
  12. if (count < 0)
  13. current = c;
  14. }
  15. return current;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement