As far as my logic goes I'm using two different arrays to store all the leafs and then compare those arrays to see if the leaves are indeed the same, but my test cases are failing (for eg. [3,5,1,6,2,9,8,null,null,7,4]
[3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]). Thanks in advance!

'''
class Solution {

```
static int array1[] = new int[50];
static int array2[] = new int[50];
static int q = 0;
static int r = 0;

 public boolean compareLeaves(int arr1[], int arr2[])
 {
     for(int i = 0; i <array1.length ;i ++)
    {
        if(array1[i] != array2[i])
        {
            return false;
        }
    }
     return true;
 }
public boolean leafSimilar(TreeNode root1, TreeNode root2) {

    if(root1 == null || root2 == null)
    {
        return false;
    }

    if(root1.left == null && root1.right == null)
    {
        array1[q] =root1.val ;
        q++;
    }

    if(root2.left == null && root2.right == null)
    {
        array2[r] =root2.val ;
        r++;
    }
    leafSimilar(root1.left,root2.left);
    leafSimilar(root1.right,root2.right);

  return compareLeaves(array1,array2);

}

```

}
'''