惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
美团技术团队
D
Docker
WordPress大学
WordPress大学
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Cloudflare Blog
Y
Y Combinator Blog
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
S
SegmentFault 最新的问题
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
A
About on SuperTechFans

The Tracks of mulder21c

Atomic Design + Storybook 적용 후기 json-server에 사용자 인증 구현하기 개발환경 WSL2 + zsh로 갈아타기 pass function as props in vue 2020년 회고 colum flexbox에서 padding bottom 문제 해결 Nuxt를 통해 보는 프론트엔드 개발자가 하는 일 Nuxt Router kebab-case 처리 JS to SCSS 변환 Nuxt + Storybook 통합 하기 2020 이직 이야기 2020 이직 이야기 2020 이직 이야기 2020 이직 이야기 Windows에서 PM2 실행 오류 해결 오픈톡 정지에 대한 카카오톡 고객센터 후기 배려에 대한 단상 학습이 잘 되지 않는 이유 웹팩 4 마이그레이션 삽질기 babel 7 업데이트 후 node_modules 패키지가 변환되지 않는다면? white space는 4px이다? 정말? 2020년 시간 관리를 위해서 도입 한 툴들 Codility Lesson 5 — PassingCars 2019년 회고 Codility Lesson 4 — MissingInteger Codility Lesson 4 — MaxCounters Codility Lesson 4 — FrogRiverOne 착각은 자유가 아닌각 세미나 진행 후기 Codility Lesson 3 — tapeEquilibrium Codility Lesson 3 — PermMissingElm
Codility Lesson — PermCheck
멀더끙 · 2019-09-30 · via The Tracks of mulder21c

authored by 멀더끙

Task description

주어진 배열이 순열이면 1 그렇지 않으면 0을 반환

How I did solve

  • 순열이라면, 1 + (N), 2 + (N-1), 3 + (N-2)이 모두 같은 값을 가질 것으로 가정

  • 주어진 배열을 오름차순으로 정렬 후, 순차적으로 더한 값을 비교해가면 누락된 숫자가 있는 경우 해당 합에서 차이가 발생할 것이므로 O(n/2)로 해결 가능할 것으로 추측

Solved Code

function solution(A) {
  const arr = A.sort( (a, b) => a - b )
  const lastEl = arr[arr.length - 1];
  const partOfSum = lastEl * (lastEl + 1) / arr.length
  const condition = Math.floor(arr.length /2 );

  for( let i = -1; ++i < condition; ) {
    if(arr[i] + arr[arr.length - 1 -i] !== partOfSum)
      return 0
  }

  return 1
}

Retrospective

  • 제출 결과 시간 복잡도가 O(N) 또는 O(N * log(N)) 으로 나오는데... 왜 그렇게 되는지 모르겠다 ;;;

  • 아직까지는 어렵지 않다.

  • 왠지 이 방법 말고 다른 더 좋은 방법이 있을 것 같은 느낌적인 느낌. 한 번 더 고민해보자.