개발/알고리즘
-
[Greedy]개발/알고리즘 2022. 9. 30. 12:29
Greedy Algorithms work step-by-step, and always choose the steps which provide immediate profit/benefit. It chooses the “locally optimal solution”, without thinking about future consequences. Greedy algorithms may not always lead to the optimal global solution, because it does not consider the entire data. The choice made by the greedy approach does not consider future data and choices. In some ..
-
[LeetCode] rotate-image (medium / javascript)개발/알고리즘 2022. 6. 30. 12:50
/** * @param {number[][]} matrix * @return {void} Do not return anything, modify matrix in-place instead. */ const rotate = function(matrix) { let answer = []; const n = matrix.length - 1; let l = 0; while (l -1; i--) { inner.push(matrix[i][l]); } matrix.push(inner); l++ } for(i=0; i
-
-
[LeetCode] Majority Element (easy / javascript)개발/알고리즘 2022. 6. 25. 11:21
const majorityElement = function(nums) { let count = {}; for(n of nums) { count[n] ? count[n]++ : count[n] = 1; if(count[n] > nums.length / 2 ) return n; } return -1; }; 배열에서 가장 많이 존재하는 요소를 찾는 문제 key가 요소이고 요소의 갯수를 value로 갖는 객체를 만들어주고 주어진 배열을 돌면서 count++; 요소의 갯수가 nums.length / 2 보다 크다면 요소 return
-
[LeetCode] [ 💩꼭 다시 풀어보기 ] Rotate Array (medium / javascript)개발/알고리즘 2022. 6. 21. 00:50
💩 꼭 다시 풀어보기 💩
-