알고리즘

    [프로그래머스] - lv.1 이상한문자 만들기

    문제설명 문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 리턴하는 함수, solution을 완성하세요. 제한 사항 문자열 전체의 짝/홀수 인덱스가 아니라, 단어(공백을 기준)별로 짝/홀수 인덱스를 판단해야합니다. 첫 번째 글자는 0번째 인덱스로 보아 짝수번째 알파벳으로 처리해야 합니다. 입출력 예 s return try hello world TrY HeLlO WoRlD 입출력 예 설명 try hello world는 세 단어 try, hello, world로 구성되어 있습니다. 각 단어의 짝수번째 문자를 대문자로, 홀수번째 문자를 소문자로 바꾸면 TrY, HeLlO, ..

    [leetcode] 136. Single Number 해설

    136. Single Number https://leetcode.com/problems/single-number/ Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. Follow up: Could you implement a solution with a linear runtime complexity and without using extra memory? Example 1: Input: nums = [2,2,1] Output: 1 Example 2: Input: nums = [4,1,2,1,2] Output: 4 Example 3: Input: nums = [1] ..

    [leet code]169. Majority Element (최다 요소)

    https://leetcode.com/problems/majority-element/ Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] Output: 2 이 문제는 배열내의 최대다수 를 구하는것이 문제이다. 여기서 중요한점은 The majority ..

    [프로그래머스] 깊이/너비 우선 탐색(DFS/BFS) - 네트워크

    참고 자료 [알고리즘] 깊이 우선 탐색(DFS) 과 너비 우선 탐색(BFS) [알고리즘] 깊이 우선 탐색(DFS) 과 너비 우선 탐색(BFS) ※ 그래프의 개념 - 정점과 간선으로 이루어진 자료구조의 일종. G = (V, E) ※ 그래프 탐색 - 하나의 정점으로부터 시작하여 차례대로 모든 �� yunyoung1819.tistory.com 나의답 function solution(n, computers) { // n: 컴퓨터 개수 // computers[i][j] // i칸의 수와 같은 j 는 무조건 1임. -> 자기 자신이기 때문에 // 한쪽이 연결되면 반대쪽은 반드시 연결되어있음 -> 2번찾을 필요없음 let answer = 0; const check = (computers, root, n) =>{ fo..