Google 태그 관리자 아이콘
반응형

algorithm 143

.leetcode(169. Majority Element)

문제 leetcode.com/problems/majority-element Majority Element - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 풀기 전 숫자를 세는 문제이기때문에 HashMap이 가장 먼저 떠올랐다. O(n)시간이 걸릴것이다. 뭔가 옛 기억이 PriorityQueue를 사용하면 될거같은데 잘 모르겠다. 직접 푼 풀이 소요시간: 11분(09:40 ~ 09:51) class Solution { public int majorityEl..

알고리즘 풀이 2021.01.02

.leetcode(136. Single Number)

문제 leetcode.com/problems/single-number/ 문제 풀기 전 정렬을 사용해서 2개씩 확인해서 다른것이 있으면 그게 하나만 있는거라고 생각했다. 직접 푼 풀이 소요시간: 22분(11:37 ~ 11:59) class Solution { public int singleNumber(int[] nums) { //정렬 Arrays.sort(nums); //n,n+1 다르면 n이 정답 int answer = 0; for (int i=0;;i+=2) { if (i == nums.length-1) { answer = nums[nums.length-1]; break; } if (nums[i] != nums[i+1]) { answer = nums[i]; break; } } return answer;..

알고리즘 풀이 2021.01.01

.leetcode(22. Generate Parentheses)

문제 leetcode.com/problems/generate-parentheses/ Generate Parentheses - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 풀기 전 stack이 필요할거같았다. 전역변수를 쓰면 편할거 같았다. end조건만 챙기고 다 돌면 풀 수 있겠다라는 생각이 들었다. 요소가 2개로 한정되어있어서 재귀를 쓸때 2번호출하는걸 로직에 넣으면 해결되겠다는 생각도 하였다. 직접 푼 풀이 class Solution { private..

알고리즘 풀이 2020.12.31
반응형