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

2.4 Anagram detection example solution 1 checking off #63

Closed
ThymeLy opened this issue Jun 11, 2019 · 1 comment
Closed

2.4 Anagram detection example solution 1 checking off #63

ThymeLy opened this issue Jun 11, 2019 · 1 comment

Comments

@ThymeLy
Copy link

ThymeLy commented Jun 11, 2019

The anagram solution 1 return true when run with print(anagramSolution1('abcd','addcb')).
I think the problem is where after running the stillOK statement that return False, upon exiting if statement, it is assigned stillOK = True, which cause it to enter the while loop even when the length does not match.

I have added an else statement after the stillOK = False and it returns the expected result.

def anagramSolution1(s1,s2):
alist = list(s2)
pos1 = 0
if len(s1) != len(s2):
stillOK = False

else:
    stillOK = True

while pos1 < len(s1) and stillOK:
    pos2 = 0
    found = False
    while pos2 < len(alist) and not found:
        if s1[pos1] == alist[pos2]:
            found = True
        else:
            pos2 = pos2 + 1

    if found:
        alist[pos2] = None
    else:
        stillOK = False

    pos1 = pos1 + 1

return stillOK
@yasinovskyy
Copy link
Contributor

Issue addressed in commit abdabef and should be closed.

@bnmnetp bnmnetp closed this as completed Aug 19, 2019
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