Observe that uniquePaths(m, n) == uniquePaths(n, m)

So swap m and n if m is bigger than n

then we do not have to do (m^2)/2 iterations, save some time, still O(mn) complexity though

public class Solution {
public int uniquePaths(int m, int n) {
if (m == 1 || n == 1) {
return 1;
}
if (m > n) {
int tmp = m;
m = n;
n = tmp;
}
int[] paths = new int[n];
for (int i = 0; i < m; i++) {
for (int j = i; j < n; j++) {
if (j == 0) {
paths[j] = 1;
} else if (i == j) {
paths[j] <<= 1;
} else {
paths[j] += paths[j-1];
}
}
}
return paths[n-1];
}
}