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

Question about Ch 1.Arrays And Strings 3.URLify #36

Open
yueran1 opened this issue May 22, 2017 · 2 comments
Open

Question about Ch 1.Arrays And Strings 3.URLify #36

yueran1 opened this issue May 22, 2017 · 2 comments

Comments

@yueran1
Copy link

yueran1 commented May 22, 2017

at line 27: int extendedLen = len + 2 * numOfSpaces;
I do not really understand why we should time 2 to the numOfSpaces? why not times 3? Cause length of space =1, and length of %20=3

@sergio-nsk
Copy link
Contributor

It is because we replace 1-char spaces with 3-chars sequences, in other words we need additionally 2 chars for each space.

Assume we have N spaces, they occupy N chars.
We need 3 * N chars in sum for N of "%20". But we have N chars already that will be free if we remove spaces, thus we need additional 3 * N - N chars , that is equal to 2 * N.

@shivamkumar001
Copy link

Can you please assign this issue to me ? I can solve this

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

No branches or pull requests

3 participants