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

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
L
LangChain Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
D
Docker
WordPress大学
WordPress大学
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
有赞技术团队
有赞技术团队
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog
博客园 - Franky

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)) 으로 나오는데... 왜 그렇게 되는지 모르겠다 ;;;

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

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