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

推荐订阅源

G
GRAHAM CLULEY
Recorded Future
Recorded Future
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
博客园 - Franky
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
N
News and Events Feed by Topic
I
Intezer
C
Check Point Blog
V
Visual Studio Blog
T
Tenable Blog
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
PCI Perspectives
PCI Perspectives
H
Help Net Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Cloudflare Blog
SecWiki News
SecWiki News
Vercel News
Vercel News
爱范儿
爱范儿
Recent Announcements
Recent Announcements
Spread Privacy
Spread Privacy
T
Threatpost
Last Week in AI
Last Week in AI
V
V2EX
O
OpenAI News
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
腾讯CDC
Forbes - Security
Forbes - Security
Microsoft Security Blog
Microsoft Security Blog
AI
AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
F
Full Disclosure
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Palo Alto Networks Blog

The Tracks of mulder21c

고정된 참조 위치 정보 선형 이미지의 최소 명도 대비 요구사항은 몇 대~ 몇? 단일 문자 단축키 (Character Key Shortcuts) 입력 방식(Input Modalities) 적응성(Adaptable) KWCAG 2.2 변경 사항 개요 Git hook으로 브랜치 이름 규칙 강제하기 댓글 시스템 remark42로 변경기 새 테마로 갈아입힘 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 — PermCheck 착각은 자유가 아닌각 세미나 진행 후기 Codility Lesson 3 — PermMissingElm Codility Lesson 3 — FrogJump 알고리즘 연습을 다시 시작했다. Codility Lesson 2 — CyclicRotation Codility Lesson 2 — OddOccurrencesInArray Codility Lesson 1 — BinaryGap 아이패드 구매 하고 3주 써 본 기록 세미나 어떻게 준비해야 할까? HTML은 웹이다 접근성 향상을 위한 이름 짓기 접근성 교육에서 자주 나오는 상위 5가지 질문
Codility Lesson 3 — tapeEquilibrium
멀더끙 · 2019-09-19 · via The Tracks of mulder21c

Task description

|(A[0] + … + A[P-1]) - (A[P] + … + A[N-1])| 최소값 찾기

How I did solve

  • 배열의 전체 합 sumOfTatal을 구함

  • A의 요소를 탐색해가며

    탐색한 요소들의 합을 구하면 A[0] + … + A[P-1]

    탐색한 요소들의 합을 전체 합에서 빼면 A[P] + … + A[N−1]

  • 둘의 차이 중 최소값을 반환

Solved Code

function solution(A) {
  const sumOfTotal = A.reduce( (acc, entry) => acc + entry, 0 )
  let  diff = Number.MAX_SAFE_INTEGER 
  
  for(let P = -1, sumOfFirstPart = 0, sumOfSecondPart = sumOfTotal; ++P < A.length - 1 ; ) {
    sumOfFirstPart += A[P]
    sumOfSecondPart -= A[P]
    
    diff = Math.min(diff, Math.abs( sumOfFirstPart - sumOfSecondPart ) )
  }
  return diff;
}

Retrospective

  • 두 번만에 풀었다.

  • 첫 번째 풀 때에는 P를 증가시키면서 배열을 slice해서 각 배열의 합의 차이를 구하는 방식으로 했더니 시간 복잡도 때문에 timeout 되더라 하하…

  • codility가 코드를 제출해야만 평가를 해주기 때문에 불편한 감이 많다. 테스트 데이터를 미리 제공해주면 그래도 좀 제출 전에 검증을 해 볼 수 있을 텐데 말이다.

Hero image from pixabay