1
var longestArithSeqLength = function (nums) {2
if (nums === null || nums.length === 0) {5
let diffMap = new Array(nums.length).fill(0).map(() => new Map());7
for (let i = 0; i < nums.length; i++) {8
for (let j = 0; j < i; j++) {9
let diff = nums[i] - nums[j];10
// if prev element has an ongoing arithmetic sequence with the same common difference11
// we simply add 1 to the length of that ongoing sequence, hence diffMap[j].get(diff) + 112
// else, we start a new arithmetic sequence, initial length is 213
diffMap[i].set(diff, diffMap[j].get(diff) + 1 || 2);14
maxLen = Math.max(maxLen, diffMap[i].get(diff));