본문 바로가기
  • soldonii's devlog

Javascript 공부/알고리즘 풀이14

(1) 코딜리티 - binaryGap 코딜리티 첫번째 문제 : binaryGap BinaryGap coding task - Learn to Code - Codility Find longest sequence of zeros in binary representation of an integer. app.codility.com 1) 정수를 2진법으로 치환하고, 2) 2진법에서 1과 1사이의 거리가 가장 긴 구간을 찾아서 그 거리를 리턴하라는 문제. 알고리즘 문제를 푸는건 왜 이렇게 어려운건지 잘 모르겠다...ㅠㅠ 검색 안 해보고 내가 머리 끙끙 싸매서 풀어보려고 했는데, 2진법 변환부터 막혔다. 처음에 생각한 방법은, n을 2로 나눈 나머지를 임의의 배열에다가 담는 과정을 n / 2가 0이 될 때까지 반복하면, 임의의 배열에 0과 1로만 이루어.. 2019. 8. 29.
자바스크립트 알고리즘(13) - vowels *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Write a function that returns the number of vowels // used in a string. Vowels are the characters 'a', 'e' // 'i', 'o', and 'u'. // --- Examples // vowels('Hi There!') --> 3.. 2019. 8. 26.
자바스크립트 알고리즘(12) - pyramids *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Write a function that accepts a positive number N. // The function should console log a pyramid shape // with N levels using the # character. Make sure the // pyramid has sp.. 2019. 8. 26.
자바스크립트 알고리즘(11) - matrix *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Write a function that accepts an integer N // and returns a NxN spiral matrix. // --- Examples // matrix(2) // [[1, 2], // [4, 3]] // matrix(3) // [[1, 2, 3], // [8, 9, 4], .. 2019. 8. 26.
자바스크립트 알고리즘(10) - fibonacci *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Print out the n-th entry in the fibonacci series. // The fibonacci series is an ordering of numbers where // each number is the sum of the preceeding two. // For example, th.. 2019. 8. 26.
자바스크립트 알고리즘(9) - steps *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Write a function that accepts a positive number N. // The function should console log a step shape // with N levels using the # character. Make sure the // step has spaces o.. 2019. 8. 26.
자바스크립트 알고리즘(8) - sentence capitalization *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Write a function that accepts a string. The function should // capitalize the first letter of each word in the string then // return the capitalized string. // --- Examples .. 2019. 8. 26.
자바스크립트 알고리즘(7) - reverseString *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Given a string, return a new string with the reversed // order of characters // --- Examples // reverse('apple') === 'leppa' // reverse('hello') === 'olleh' // reverse('Gree.. 2019. 8. 26.
자바스크립트 알고리즘(6) - reverseInt *Udemy의 "The Coding Interview Bootcamp: Algorithms + Data Structures" 강의에서 학습한 내용을 정리한 포스팅입니다. *https://soldonii.github.io에서 작성한 글을 티스토리로 옮겨온 포스팅입니다. *자바스크립트를 배우는 단계라 오류가 있을 수 있습니다. 틀린 내용은 댓글로 말씀해주시면 수정하겠습니다. 감사합니다. :) 지문 // Given an integer, return an integer that is the reverse // ordering of numbers. // --- Examples // reverseInt(15) === 51 // reverseInt(981) === 189 // reverseInt(500) === 5 .. 2019. 8. 26.