Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 23.cpp #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Create 23.cpp #54

wants to merge 3 commits into from

Conversation

John-Weak
Copy link
Contributor

No description provided.

@Animesh-Ghosh
Copy link
Member

Use stacks.

@John-Weak
Copy link
Contributor Author

Use stacks.

Will it reduce time complexity?How will it make the solution better please elaborate.

@Animesh-Ghosh
Copy link
Member

You ever done Infix to Post-fix? We use stacks because they are helpful in expression evaluation. This solution works because there isn't any expression within the braces.

But if you use stacks, even if there are any expressions between the braces, you can just count the number of remaining braces after the matching braces have been popped.

TL;DR:

Solution works, expected solution to use stacks.

Some comments in the source code would have been better. 🙂

Copy link
Member

@Animesh-Ghosh Animesh-Ghosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solution works, merge-able. Next time use stacks.

Don't close this PR.

@John-Weak
Copy link
Contributor Author

John-Weak commented Oct 16, 2019 via email

Copy link
Member

@Animesh-Ghosh Animesh-Ghosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make some changes, OK?

I'll merge it then.

Next time, stack time.

23.cpp Outdated
int cases,cases1;
cin>>cases;
cases1=cases;
int ar[cases];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this for printing the output.

23.cpp Outdated
flag+=2;
i++;
}
ar[cases-cases1]=leng-flag;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just print the output using cout.

int diff = length - flag; // flag? there could have been a better word
cout << diff << "\n;

23.cpp Outdated
Comment on lines 26 to 27
for(int i=0;i<cases;i++)
cout<<ar[i]<<endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this, it's not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants