Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded Anagram.java #1646
Open
Added Anagram.java #1646
Conversation
strings/Anagram.java
Outdated
| Scanner scan=new Scanner(System.in); | ||
| String a=scan.nextLine(); | ||
| String b=scan.nextLine(); | ||
| boolean ana=true; |
Comment on lines
5
to
8
rbshealy
Oct 9, 2020
Contributor
Fix indentation
Fix indentation
strings/Anagram.java
Outdated
| for(char c : a.toCharArray()) | ||
| { | ||
| int i=(int)c; | ||
| u[i]++; | ||
| } | ||
| for(char c : b.toCharArray()) | ||
| { | ||
| int i=(int)c; | ||
| v[i]++; | ||
| } |
Comment on lines
14
to
23
rbshealy
Oct 9, 2020
Contributor
What is going on here?
What is going on here?
sj056
Oct 10, 2020
Author
- Here i have initialized 2 arrays u and v first for string a and second for b .
- Converted the strings to lowercase.
- Then alternatively, while converting the char of the string to int(we'll get the ASCII value of that character) then
incrementing that particular index of the string by 1(for eg : if char is 'a' then we'll increment the 97th(ASCII value of
a) index of the array).
- We'll follow these steps for both the strings (hence 2 for loops are used) .
- At the end we'll check if both the arrays are equal then the strings are anagram of each other else not.
- Here i have initialized 2 arrays u and v first for string a and second for b .
- Converted the strings to lowercase.
- Then alternatively, while converting the char of the string to int(we'll get the ASCII value of that character) then
incrementing that particular index of the string by 1(for eg : if char is 'a' then we'll increment the 97th(ASCII value of
a) index of the array). - We'll follow these steps for both the strings (hence 2 for loops are used) .
- At the end we'll check if both the arrays are equal then the strings are anagram of each other else not.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.


Describe your change:
References
Checklist:
Fixes: #{$ISSUE_NO}.