LeetCode Remove All Adjacent Duplicates In String Solution Explained - Java
Vložit
- čas přidán 23. 08. 2019
- The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
AlgoCademy - algocademy.com/?referral=nick...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
Follow My Twitter - / nicholaswwhite
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nickwwhite?locale.x...
Become A Member - / @nickwhite
#coding #programming #softwareengineering - Věda a technologie
short concise and easy to understand. Your way of teaching is perfect. Please keep it up
You're my hero man!
How do you handle when char is repeated odd no of times like if string is abbbac
"abac"
should be the output for this
I know what you're thinking
output should have been "c" according to you
but this problem is diffenret
That clap at the beginning blew my ear off 😅
very helpful. Thanks a lot !
Such good stuff in every video
Very very helpful.
Thank you!!
Request tutorial graph like a MST, djikstra shortest path
Originally, I used two pointers instead of stack and it turned out to be really inefficient compared to stack. I really appreciate your stack explanation! :)
I would like to see your solution if you dont mind please
O(1) space solution ...
Loop until arr(i) ==arr(i+1) then place 2 pointers a and b at I+2 and i-1 respectively ,and check if elements are equal at those indices, if yes keep expanding the pointers a and b until the elements are not equal then delete.repeat everything till we reach the end of string
nice
U r doing a very very great job thanx that I have found u in youtube.
I love your videos..
Love from India..❤💌
the the way you programmed this question it is genius...
You are Amazing dude thankyou
what was that noise in the starting of the video !!
I thought the sound came from my side, your comment just assured me that I am safe here 😂
I have never used stack with indices, can someone share me some problems, which use the same. Thanks.
why using a char[] as stack instead of using STACK ADT?
wondering too!!
I did this easily using a Stack
class Solution {
public String removeDuplicates(String s) {
Stack stack = new Stack();
StringBuilder sb = new StringBuilder();
for(int i=0;i
thanks bro
u are the best
7:25 how does string from 0,2 returns c,a. Instead of 0,2 it should be 0,1?
0 is inclusive, 2 is exclusive
@@gaurav91pandey actually the 2 in (stack, 0, 2 ) is the offset and not the exclusive index. 0 is the starting index and 2 here tells about the length from index 0 till which it will copy from stack into the new string.
"aaaaaaaa" this doesn't work
Can do with inplace string manipulation , without using extra memory (credit to you as I learnt this trick from your previous video, so thank you! :) )
I would like to see your solution if you dont mind please
Brother you didn’t write a 0 assignment in case there’s a duplicate how can stack change then ....
It does not work with aaab result is ab should be b
space is o(1)
string removeDuplicates(string s) {
int i = 0, n = s.length();
for (int j = 0; j < n; ++j, ++i) {
s[i] = s[j];
if (i > 0 && s[i - 1] == s[i]) // count = 2
i -= 2;
}
return s.substr(0, i);
}
This has SC: O(1)
It doesn't work for TC aabbccccbapq
wrong solution bro
my code is showing TLE for 9000+ characters
i like your videos, but this solution doesn't work
your code doesnt work for "geeksforgeek"
*With no extra space*
---------------------------------
StringBuilder sb = new StringBuilder(s);
int i = 0;
while(i0)
i --;
}
else{
i++;
}
}
return sb.toString();
acaaabssscp this doesn't work, I believe u thought of only two consecutive are adjacent!! Btw np , thanks keep posting
seriously you can figure out without o(n) spaces ? , you can iterate the string with 2 a and b pointers . stop the first pointer a when a and a-1 index is equal , then paste a+1th index item at a-1 , also make b=a+1; a=a-2;..... keep going until list ends.
Do you have the code for this approach?
Without extra space
class Solution {
public String removeDuplicates(String S) {
//String s="abbaca";
for(int i=0;i
why this line two times ?
s=s.substring(0,i)+s.substring(i+1, s.length());
Also, Can you please confirm if the solution is working for the input "abbaca"?