[javascript] daily coding section3 24, 25

KoEunseo·2022년 10월 5일
0

Daily_Coding

목록 보기
16/21

24

const isSubsetOf = function (base, sample) {
  //sample[i] === base[0]~base[base.length-1]
  // basecase : sample[i] === base[j]
  // recursivecase : sample[i] !== base[j]
  //base = [1,2,3,4,5]
  //sample = [1,3]
  //sample[i] === base[j] ? isPart = true : isSubsetOf(sample[i+1] === base[j])

  const newSet = [...new Set(base.concat(sample))];

  if(base.length === newSet.length){
    return true;
  } else {
    return false;
  }
};

25

let tiling = function (n) {
  //세로길이 2 가로길이 n인 보드
  // 2 by 1 크기의 타일로 보드를 채우는 모든 경우의 수 리턴
  // n:1 = 1
  // n:2 = 2
  // n:3 = 3
  // n:4 = 5
  // 뒤에 오는 패턴은 앞에 온 2가지의 타입의 조합이다. 세로로만 조합, 가로로만 조합, 가로 * 세로조합
  // 가로길이 n = (n-1)세로패턴 + (n-2)가로패턴
  //n=(n-1)+(n-2)
  const memo = [];

  const recur = (n) => {
    if(memo[n]) return memo[n];
    if(n < 3) return n;

    memo[n] = recur(n-1) + recur(n-2);
    return memo[n];
  }
  return recur(n);

};
profile
주니어 플러터 개발자의 고군분투기

0개의 댓글