Skip to content

Commit bf743b2

Browse files
authored
Merge pull request algorithm004-01#430 from AceXu/master
666-week 02
2 parents caee27c + 70f669d commit bf743b2

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public boolean isAnagram(String s, String t) {
3+
//判断字符长度是否相等
4+
if(s.length() != t.length()) {
5+
return false;
6+
}
7+
8+
if (s.length() == 0 || t.length() == 0) {
9+
return false;
10+
}
11+
12+
//统计每个字母出现的频次,字符相减
13+
int[] nums = new int[26];
14+
for (int i = 0; i < s.length(); i++) {
15+
nums[s.charAt(i) - 'a']++;
16+
nums[t.charAt(i) - 'a']--;
17+
}
18+
19+
for (int num : nums) {
20+
if (num != 0) {
21+
return false;
22+
}
23+
}
24+
25+
return true;
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 二叉树中序遍历
3+
**/
4+
class Solution {
5+
public List<Integer> inorderTraversal(TreeNode root) {
6+
List < Integer > res = new ArrayList < > ();
7+
helper(root, res);
8+
return res;
9+
}
10+
11+
//不是很懂,默写代码
12+
public void helper(TreeNode root, List < Integer > res) {
13+
if (root != null) {
14+
if (root.left != null) {
15+
helper(root.left, res);
16+
}
17+
res.add(root.val);
18+
if (root.right != null) {
19+
helper(root.right, res);
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)