File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments