Skip to content

Instantly share code, notes, and snippets.

@David-Hackro
Last active November 21, 2017 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save David-Hackro/d8dad4277322f6735af4dae4a40f0b0d to your computer and use it in GitHub Desktop.
Save David-Hackro/d8dad4277322f6735af4dae4a40f0b0d to your computer and use it in GitHub Desktop.
exercises in java
package crackingcodeinterview;
public class Exercise {
static String textString = "this is a random text of example";
public static void main(String[] args) {
filterLetters(0, "");
}
public static void filterLetters(int position, String letters) {
if (position != textString.length()) {
boolean p = false;
for (int i = 0; i < letters.length(); i++) {
if (letters.charAt(i) == textString.charAt(position)) {
p = true;
break;
}
}
if (!p) {
letters += textString.charAt(position);
}
position++;
filterLetters(position, letters);
} else {
System.out.println(letters);
}
}
}
@David-Hackro
Copy link
Author

i need change this solution, becase i cant use the substring because create a new string constantly :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment