간단하게는 minimum value 로 each index를 subtract할 수 있는 갯수를 구하는 문제. Solution 1 in Javascript const arr = [5, 3, 2, 2, 2, 8] function cutTheSticks(arr) { //sort the array let sorted = arr.sort(); //set index[0] to a min let min = sorted[0]; console.log(sorted.length); for (let i = 0; i min) { min = sorted[i]; //change min to next shortest min console.log(sorted.le..
주어진 array 에서 최대로 중복되는 index를 제외한 나머지 index의 수를 구하는 문제 solution 1. 중복을 허용하지 않는 hashMap 을 선언. 2. 주어진 arr를 hashMap안에 넣으면서 중복되는 값이 있으면 value의 값이 1씩 증가하게 한다. 3. maximum value의 수를 찾는다. 4. 전체 array길이에서 찾아낸 maximum value를 return한다. Solution 1 -object를 이용하는 traditional way 말고 built-in function 인 Map을 이용하는 방식. function equalizeArray(arr) { //let arrObj = {}; //initialize object which is for hashmap. //but..
Binary Tree(이진트리) 의 node와 그 node의 children을 invert 하는 문제. node뿐 아니라 그 밑에 속해있는 자식들까지 swipe해야하기때문에 recursive function(재귀함수)을 사용해야한다. Solution 1 var invertTree = function(root) { //재귀의 정지값->root가 있을때 까지. if(root){ swap(root); //swipe children invertTree(root.left); //subtree의 children에게도 같은 process적용을 위해 recursive invertTree(root.right); } return root; }; var swap = function(root){ let left = root...
기존의 git을 삭제 후 다시 설정하는 법. 잘못 생성한 폴더로 가서 .git 폴더 전체 삭제 rm -rf .git/ 원하는 폴더로 이동 후 git init git add -A git commit -m "commit message" USERNAME@github.com/USERNAME/REPOSITORY_NAME.git git push -u origin master git add -A 를 하니 에러나던게 사라지고 잘 push됨. 만약에 git repository의 상위 폴더로 옮기고 싶을 경우. 전체 폴더를 복사해서 상위로 옮기는 방법을 사용!
Solution in Javascript const n = 3; function viralAdvertising(n) { let k = 5; let j = 0; let sum = 0; for(let i = 0; i < n; i++){ j = Math.floor(k/2); k = j * 3; sum+=j; } console.log(sum); } viralAdvertising(n); *Use Math.floor() to get quotient. Reference www.hackerrank.com/challenges/strange-advertising/problem
- Total
- Today
- Yesterday
- 프로그래머스 알고리즘
- javascript
- java
- spring boot application
- C++
- Object type casting
- equals()
- ... in Javascript
- rest parameter
- math.max
- math.abs
- HashMap
- easy algorithm
- substring()
- 프로그래머스 알고리즘문제
- repeat()
- hackerrank javascript solution
- 알고리즘
- algorithm
- code refactoring
- HackerRank Algorithm
- easy javascript algorithm
- hackerrank javascript
- Collection Framework
- compareTo()
- hackerrank
- 프로그래머스
- Javascript Algorithm
- hackerrank solution
- string class in java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |