본문 바로가기 메뉴 바로가기

Studying programming

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

Studying programming

검색하기 폼
  • Jimin's Programming (194)
    • Algorithms (54)
    • JavaScript (16)
    • Vue.js (3)
    • Node.js (3)
    • React.js (7)
    • React Native (0)
    • Spring Boot (13)
    • JAVA (58)
    • C++ (17)
    • Programming (19)
    • Computer basics (4)
  • 방명록

algorithm (11)
smallest distance

find the smallest distance in a given array. const arr = [1, 4, 2, 2, 1, 5]; function smallestDistance(arr) { const distanceArray = []; for (let i = 0; i < arr.length; i++) { if (arr.lastIndexOf(arr[i]) !== arr.indexOf(arr[i])) { let distance = arr.lastIndexOf(arr[i]) - arr.indexOf(arr[i]) //get the distance distanceArray.push(distance); //push to new array } } distanceArray.sort() //sort consol..

Algorithms 2021. 1. 16. 21:27
Bon Appétit

Solution in JavaScript const arr = [3, 10, 2, 9]; const k = 1; const b = 12; function solve(bill, k, b) { bill[k] = 0; // 해당 index를 제외하고 시작. let sum = bill.reduce((x,y) => x + y); // reduce로 전부 sum let each = sum / 2; if(each === b){ console.log('Bon Appetit'); } else { console.log(b - each); } } solve(arr, k, b); //loop해서 k의 index를 제외하는 것 -> 해당 index에 0을 넣기.(이 생각을 내가 왜 못했을까!) Reference www.hack..

Algorithms 2020. 9. 12. 00:17
Birthday Chocolate

Solution in JavaScript const arr = [1, 2, 1, 3, 2]; const d = 3; const m = 2; function birthday(s, d, m) { let result = 0; for (let i = 0; i x + y) === d) { result++; } } //return result; console.log(result); } birthday(arr, d, m); //1. 길이만큼 loop을 돌려야하나? -> 2번 //..

Algorithms 2020. 9. 11. 22:11
Divisible Sum Pairs

Solution in JavaScript const arr = [1, 3, 2, 6, 1, 2]; const k = 3; const n = arr.length; function Divisible_Sum_Pairs(n, k, ar) { let num = 0; for(let i = 0; i < n; i++) { //condition 'i < j' 는 i보다 j가 index number로서 우선할 수 없다는 의미지 값이 커야한다는 의미가 아님. //문제 제대로 읽기! for(let j = (i + 1); j < n; j++){ if((ar[i] + ar[j]) % k === 0){ // 계산순서위한 () 잊지말것. ++num; } } } console.log(num); } Divisible_Sum_Pairs(..

Algorithms 2020. 9. 5. 10:22
Breaking the Records

Solution in JavaScript const scores = [10, 5, 20, 20, 4, 5, 2, 25, 1]; function breakingRecords(scores) { let [max, min] = [scores[0], scores[0]]; //중복배열로 선언 let [maxCount, minCount] = [0, 0]; for (let i = 1; i max) { //array로 넣어야지... max = scores[i]; maxCount++ } if (scores[i] < min) { min = scores[i]; minCount++ } } return [maxCount, minCount]; //두개 이상의 ..

Algorithms 2020. 9. 4. 21:26
Birthday Cake Candles

Problem You are in charge of the cake for your niece's birthday and have decided the cake will have one candle for each year of her total age. When she blows out the candles, she’ll only be able to blow out the tallest ones. Your task is to find out how many candles she can successfully blow out. For example, if your niece is turning 4years old, and the cake will have 4candles of height 4,4,1,3 ..

Algorithms 2020. 8. 16. 21:23
이전 1 2 다음
이전 다음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
  • javascript
  • math.abs
  • C++
  • ... in Javascript
  • compareTo()
  • HashMap
  • Object type casting
  • 프로그래머스 알고리즘
  • rest parameter
  • easy javascript algorithm
  • substring()
  • java
  • repeat()
  • spring boot application
  • hackerrank solution
  • equals()
  • hackerrank javascript solution
  • math.max
  • easy algorithm
  • 프로그래머스
  • Javascript Algorithm
  • 프로그래머스 알고리즘문제
  • Collection Framework
  • 알고리즘
  • hackerrank javascript
  • hackerrank
  • string class in java
  • algorithm
  • HackerRank Algorithm
  • code refactoring
more
«   2025/06   »
일 월 화 수 목 금 토
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
29 30
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바