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

推荐订阅源

K
Kaspersky official blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
N
News and Events Feed by Topic
Cloudbric
Cloudbric
B
Blog
Cisco Talos Blog
Cisco Talos Blog
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
V
Visual Studio Blog
A
Arctic Wolf
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
S
Security @ Cisco Blogs
博客园 - 聂微东
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
量子位
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tenable Blog
月光博客
月光博客
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
D
Docker
www.infosecurity-magazine.com
www.infosecurity-magazine.com
雷峰网
雷峰网
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Help Net Security
Help Net Security
D
DataBreaches.Net

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 3 — FrogJump 알고리즘 연습을 다시 시작했다. Codility Lesson 2 — CyclicRotation Codility Lesson 2 — OddOccurrencesInArray Codility Lesson 1 — BinaryGap 아이패드 구매 하고 3주 써 본 기록 세미나 어떻게 준비해야 할까? HTML은 웹이다 접근성 향상을 위한 이름 짓기 접근성 교육에서 자주 나오는 상위 5가지 질문 접근 가능한 숨김 텍스트 깃북 파일 저장 시 오류 문제 해결 크로스 브라우징이란? 블로그 테마 만들기 시작 2018년 회고 학습에 대한 오해 모르는 사람에게 질문할거면 예의 좀 지켜라 파이썬으로 웹 크롤러 만들기 해쉬 링크 오프셋 조정하기
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)) 으로 나오는데... 왜 그렇게 되는지 모르겠다 ;;;

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

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