We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 526b2d1 + 92b8687 commit fe91b19Copy full SHA for fe91b19
1 file changed
ValidAnagram.java
@@ -0,0 +1,31 @@
1
+/**
2
+ * Given two strings s and t , write a function to determine if t is an anagram of s.
3
+ * <p>
4
+ * Example 1:
5
6
+ * Input: s = "anagram", t = "nagaram"
7
+ * Output: true
8
+ * Example 2:
9
10
+ * Input: s = "rat", t = "car"
11
+ * Output: false
12
+ */
13
+public class ValidAnagram {
14
+
15
+ public boolean isAnagram(String s, String t) {
16
+ if (s.length() > t.length()) {
17
+ return false;
18
+ }
19
+ char[] secondWord = t.toCharArray();
20
+ for (char letter : secondWord) {
21
+ if (!isContainsLetter(s, letter)) {
22
23
24
25
+ return true;
26
27
28
+ private boolean isContainsLetter(String word, char specificLetter) {
29
+ return word.contains(String.valueOf(specificLetter));
30
31
+}
0 commit comments