Stack Introduction

preview_player
Показать описание
Related videos:

Data Structures Source Code:

Рекомендации по теме
Комментарии
Автор

Coding the parentheses check problem on leetcode was so easier after watching this video. Just some syntax error but an efficient solution. Thank you William!

anj
Автор

Thanks a bunch for creating all these awsome videos on data structures!

kasperbaun
Автор

I'm so proud of when my country has one problem which all dev can know is Hanoi tower. 🙌🙌🙌🙌❤❤❤❤

vovanhung
Автор

Shouldn’t stacks be o(n) in size since it holds n items

nomd
Автор

Good explanation. But, I think pseudo-code for valid parenthesis problem is incomplete or incorrect or I have not understood correctly. Can you please provide the actual code? Below is what I implemented and with your pseudo code if we have input as "()", then it will try to getReversedBracket(")") i.e for ")" this also, so I am confused with that.
public boolean isValid(String s) {
Stack stack = new Stack();
for( int i=0; i < s.length(); i++ ){
String c =
if( c.equals("{") || c.equals("(") || c.equals("[") ){
stack.push(c);
}
else{
if( !stack.isEmpty()){
String rev =
if( c.equals(rev) )
stack.pop();
else
return false;
}
else
return false;
}
}
if( stack.isEmpty())
return true;
else
return false;
}

public String getReverseBracker(String s){
if(s.equals("{"))
return "}";
else if(s.equals("("))
return ")";
else if(s.equals("["))
return "]";
return "";
}

vinayshivakumar