Skip to content

Fixes(#2884) #2955

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

Merged
merged 40 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
38daad8
Fixes: #{2391}
siddhant2002 Dec 5, 2021
a417229
Fixes #(2391)
siddhant2002 Dec 7, 2021
4cd2497
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Dec 8, 2021
e3c28dc
Delete String_Comparision.java
siriak Dec 9, 2021
0e97ad8
Merge branch 'master' into master
siriak Dec 9, 2021
f27eff4
Fixes: #{2820}
siddhant2002 Dec 14, 2021
bdc2a8a
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Dec 14, 2021
9e77af5
Fixes #{2820}
siddhant2002 Dec 14, 2021
3cacb76
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 Dec 14, 2021
a192de6
Fixes(#2450)
siddhant2002 Dec 20, 2021
516c7b9
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Dec 20, 2021
10e58e3
string Codes removed
siddhant2002 Dec 21, 2021
c62aea7
Merge branch 'master' into master
siddhant2002 Dec 22, 2021
d24fdf2
fixes(#2882)
siddhant2002 Dec 22, 2021
30615b3
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 Dec 22, 2021
20261bf
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Jan 18, 2022
f9fc81e
Fixes(2882)
siddhant2002 Jan 19, 2022
86b0102
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 Jan 19, 2022
f5a0937
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Jan 20, 2022
a214d7f
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Jan 22, 2022
e136a3b
Fixes(#2877)
siddhant2002 Jan 22, 2022
e5541ed
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 Jan 22, 2022
6220cee
Fixes(#2877)
siddhant2002 Feb 11, 2022
ab73827
Fixes(#2877)
siddhant2002 Feb 12, 2022
17009fc
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Feb 12, 2022
f903458
Fixes(#2877)
siddhant2002 Feb 12, 2022
2467c8c
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 Feb 12, 2022
ababfa4
Fixes(#2877)
siddhant2002 Feb 13, 2022
255e4df
Fixes(#2877)
siddhant2002 Feb 13, 2022
a404bdc
Fixes(#2873)
siddhant2002 Feb 16, 2022
fd6dd28
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Feb 16, 2022
ddad2bd
Merge branch 'master' into master
siriak Feb 19, 2022
6902ee7
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Feb 19, 2022
3b541ff
Merge branch 'TheAlgorithms:master' into master
siddhant2002 Feb 21, 2022
484d122
Fixes(#2884)
siddhant2002 Feb 22, 2022
08819aa
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 Feb 22, 2022
26ac95e
Fixes(#2884)
siddhant2002 Feb 22, 2022
5ceffa0
Fixes(#2884)
siddhant2002 Feb 22, 2022
e0c8cc9
Fixes(#2884)
siddhant2002 Feb 22, 2022
31826c0
Fixes(#2884)
siddhant2002 Feb 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes #(2391)
  • Loading branch information
siddhant2002 committed Dec 7, 2021
commit a4172291f5745bd11c02580f9468225edf07bf2c
44 changes: 22 additions & 22 deletions src/main/java/com/thealgorithms/strings/Anagrams.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public static void main(String args[]) {
String second = "lead";
// All the below methods takes input but doesn't return any output to the main method.
Anagrams nm=new Anagrams();
nm.approach2(first, second); /* To activate methods for different approaches*/
nm.approach1(first, second); /* To activate methods for different approaches*/
nm.approach3(first, second); /* To activate methods for different approaches*/
nm.approach4(first, second); /* To activate methods for different approaches*/
System.out.println(nm.approach2(first, second)); /* To activate methods for different approaches*/
System.out.println(nm.approach1(first, second)); /* To activate methods for different approaches*/
System.out.println(nm.approach3(first, second)); /* To activate methods for different approaches*/
System.out.println(nm.approach4(first, second)); /* To activate methods for different approaches*/

/**
* OUTPUT :
Expand All @@ -37,11 +37,11 @@ public static void main(String args[]) {
*/
}

void approach1(String s, String t)
boolean approach1(String s, String t)
{
if (s.length() != t.length())
{
System.out.println(false);
return false;
}
else
{
Expand All @@ -51,19 +51,19 @@ void approach1(String s, String t)
Arrays.sort(d); /* In this approach the strings are stored in the character arrays and both the arrays are sorted. After that both the arrays are compared for checking anangram */
if (Arrays.equals(c, d))
{
System.out.println("Anagram");
return true;
} else
{
System.out.println("Not Anagram");
return false;
}
}
}

void approach2(String a, String b)
boolean approach2(String a, String b)
{
if(a.length()!=b.length())
{
System.out.println("Not Anagram");
return false;
}
else
{
Expand All @@ -73,7 +73,7 @@ void approach2(String a, String b)
{
m[c-'a']++;
}
// In this approach the frequency of both the strings are stored and after that the frequencies are iterated from 0 to 26(from 'a' to 'z' ). If the frequencies match then anagram message is displayed
// In this approach the frequency of both the strings are stored and after that the frequencies are iterated from 0 to 26(from 'a' to 'z' ). If the frequencies match then anagram message is displayed in the form of boolean format
// Running time and space complexity of this algo is less as compared to others
for(char c:b.toCharArray())
{
Expand All @@ -83,18 +83,18 @@ void approach2(String a, String b)
{
if(m[i]!=n[i])
{
System.out.println("Not Anagram");
return false;
}
}
System.out.println("Anagram");
return true;
}
}

void approach3(String s, String t)
boolean approach3(String s, String t)
{
if(s.length()!=t.length())
{
System.out.println("Not Anagram");
return false;
}
// this is similar to approach number 2 but here the string is not converted to character array
else
Expand All @@ -110,19 +110,19 @@ void approach3(String s, String t)
for(int i=0;i<26;i++)
{
if(a[i]!=b[i])
System.out.println("Not Anagram");
return false;
}
System.out.println("Anagram");
return true;
}
}

void approach4(String s, String t)
boolean approach4(String s, String t)
{
if(s.length()!=t.length())
{
System.out.println("Not Anagram");
return false;
}
// This approach is done using hashmap where frequencies are stored and checked iteratively and if all the frequencies of first string match with the second string then anagram message is displayed
// This approach is done using hashmap where frequencies are stored and checked iteratively and if all the frequencies of first string match with the second string then anagram message is displayed in boolean format
else
{
HashMap<Character,Integer> nm=new HashMap<>();
Expand All @@ -141,10 +141,10 @@ void approach4(String s, String t)
{
if(!nm.get(c).equals(kk.get(c)))
{
System.out.println("Not Anagram");
return false;
}
}
System.out.println("Anagram");
return true;
}
}
}
Empty file.