Posted By

bassemZohdy on 03/19/10


Tagged

String


Versions (?)

Deleted Chars


 / Published in: Java
 

  1. //"abc" "bc" -> [ 0 ]
  2. //"abc" "c" -> [ 0, 1 ]
  3. //"abac" -> "aac" -> [ 1 ]
  4. //"aabc" -> "abc" -> [ 0 ] *or* [ 1 ]
  5.  
  6. public static List getDeletedChar(String a, String b) {
  7. List results = new ArrayList();
  8. int charIndex;
  9. int cursorPos = 0;
  10. for (int i = 0; i < b.length(); i++) {
  11. charIndex = a.indexOf(b.charAt(i), cursorPos);
  12. for (int j = cursorPos; j < charIndex; j++) {
  13. results.add(j);
  14. }
  15. cursorPos = charIndex + 1;
  16. }
  17. while(cursorPos < a.length()){
  18. results.add(cursorPos++);
  19. }
  20.  
  21. return results;
  22. }

Report this snippet  

You need to login to post a comment.