개발
-
-
[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
-
[리팩토링] - (2) 코드에서 나는 악취개발 2022. 6. 21. 01:00
Code smells 코드에서 나는 악취란 단순히 프로그램의 버그를 뜻하지 않는다. 중복되거나 복잡한 패턴들 혹은 다른 코드에 너무 의존적인 코드 등 잘못된 설계 일지라도 겉으로 보기에는 프로그램이 문제없이 동작 할수도 있다. 버그와 프로그램의 실패의 리스크를 증가시키는 디자인을 통틀어서 코드에서 나는 악취라고 표현한다. ( 이 용어는 Kent Back 에 의해 처음 사용되었다. ) Types of code smells 1. 기이한 이름 (Mysterious Name) There are only two hard things in Computer Science: cache invalidation and naming things Phill Karlton 적절한 변수,함수 등의 네이밍이 코드를 더 이해하기 쉽..
-
[LeetCode] [ 💩꼭 다시 풀어보기 ] Rotate Array (medium / javascript)개발/알고리즘 2022. 6. 21. 00:50
💩 꼭 다시 풀어보기 💩
-
-
[Big O]개발/자료구조 2022. 6. 20. 00:24
Big O 빅오 표기법이란 입력된 값에 의해 시간 복잡도와 공간복잡도를 측정 할수 있는 수학전 표현 방식이다. Constant time : O (1) function add (num1, num2) { return num1 + num2; } For the above function, there will always be two inputs: num1 and num2. The only operation that will ever be done on them is simple addition. This means that no matter what the input, it will always take a very small amount of time to complete the function and the..