2ndchar
JCHJava Community | Help. Code. Learn.
•Created by 2ndchar on 4/4/2025 in #java-help
leetcode like problem? optimization of nesting tags
i've asked for help with this problem elsewhere, and someone made the observation that i can manually cut down on the tags by deleting any tags that match the pattern of </??><??>
it seems to me that i need to save the previous character's tags first
and then check the current tags against the first one and print accordingly
for example
(to cut down on complexity, pretend the numbers represent tags like <b>, and the numbers just represent their correct order)
if the previous character's tags was 1 2 3 4 5
and the current character's tag was 1 2 3
so, unoptimized, it would look like
1 2 3 4 5
(A)
5 4 3 2 1 1 2 3 (B)
3 2 1
optimized, it would look like
1 2 3 4 5 (A)
5 4 (B)
3 2 1
one approach i haven't tried yet is looking at this problem literally step by step
at (A)
, the program knows it has tags 1 2 3 4 5
since it's at the beginning, it prints all of 1 2 3 4 5
then it looks at the next letter, (B)
, and its tags are 1 2 3
i see that 4 and 5 is missing, so i print out 5 and 4
and then i look at the next letter and see that there's none
so i print out 3 2 16 replies
JCHJava Community | Help. Code. Learn.
•Created by 2ndchar on 4/4/2025 in #java-help
leetcode like problem? optimization of nesting tags
6 replies
JCHJava Community | Help. Code. Learn.
•Created by 2ndchar on 4/10/2024 in #java-help
reader.readLine() not working as expected
thx for that
10 replies
JCHJava Community | Help. Code. Learn.
•Created by 2ndchar on 4/10/2024 in #java-help
reader.readLine() not working as expected
wait i think thats it actually
10 replies
JCHJava Community | Help. Code. Learn.
•Created by 2ndchar on 4/10/2024 in #java-help
reader.readLine() not working as expected
oh wait is it because of the while loop, whenever the for loops end, it runs again because of the while loop?
10 replies
JCHJava Community | Help. Code. Learn.
•Created by 2ndchar on 4/10/2024 in #java-help
reader.readLine() not working as expected
uhh are you saying that i dont need two for loops?
10 replies