Skip to content

Instantly share code, notes, and snippets.

@zaidw21
Last active April 26, 2020 16:23
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 zaidw21/2af65170f5c3a96763a447842609e3b8 to your computer and use it in GitHub Desktop.
Save zaidw21/2af65170f5c3a96763a447842609e3b8 to your computer and use it in GitHub Desktop.
Test
static class Entity {
char character;
int frequency;
Entity(char p, int q) {
character = p;
frequency = q;
}
}
List<String> list = new ArrayList<>();
Stack<Entity> st = new Stack<>();
int i = 0;
for (i = 0; i < inputArray.size(); i++) {
char x = inputArray.get(i).charAt(0);
if (!st.isEmpty() && st.peek().frequency == burstLength) {
char curr = st.peek().character;
while (!st.isEmpty() && st.peek().character == curr)
st.pop();
}
if (!st.isEmpty() && st.peek().character == x) {
Entity newTop = new Entity(x, st.peek().frequency + 1);
st.push(newTop);
}
else {
Entity newTop = new Entity(x, 1);
st.push(newTop);
}
}
if (!st.isEmpty() && st.peek().frequency == burstLength) {
char curr = st.peek().character;
while (!st.isEmpty() && st.peek().character == curr)
st.pop();
}
while (!st.isEmpty())
list.add(Character.toString(st.pop().character));
Collections.reverse(list);
return list;
@zaidw21
Copy link
Author

zaidw21 commented Apr 26, 2020

static class Entity {
char character;
int frequency;

	Entity(char p, int q) {
		character = p;
		frequency = q;
	}
}	

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