본문 바로가기

코딩테스트/Leet Code 10

[LeetCode] 392. Is Subsequence - 자바스크립트 [ 문제 ] leetcode.com/problems/is-subsequence/ Is Subsequence - 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 [ 아이디어 ] DP 문제라고 해서 풀어보고는 있는데 DP의 개념으로 풀기보다는 일반 정답을 맞추려는 목적으로 했다.#1 일반 풀이의 경우에도 시간복잡도가 크지 않다. substring의 문자열을 하나씩 비교하는데 mainstring에서 해당 문자열이 있나 확인하고 있을 때는 mainstring을 slice.. 2021. 4. 10.
[LeetCode] 121. Best Time to Buy and Sell Stock - 자바스크립트 [ 문제 ] leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - 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 [ 아이디어 ] 동적계획법, DP에 대한 문제였습니다. easy 문제답게 DP에서 메모리제이션 기법을 활용해서 문제를 풀 수 있었습니다. Discuss 를 보면 이 문제는 DP가 아니라는 말도 보이지만 기본적인 DP를 설명하기에 좋은 문제가 아닐까.. 2021. 4. 9.
[LeetCode] 자바 48. Rotate Image 문제는 '정렬을 시계방향으로 90도 회전하라' 입니다 첫번째. class Solution { public void rotate(int[][] matrix) { int swap = 0; int size = matrix.length; int[][] swapMartix = deepCopy(matrix, matrix.length); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { matrix[j][size - 1 - i] = swapMartix[i][j]; } } } public static int[][] deepCopy(int[][] original, int n) { if (original == null) { return null; } in.. 2020. 8. 12.
[LeetCode] 자바 581. Shortest Unsorted Continuous Subarray 문제는 '정렬되지 않은 부분을 찾아라' 입니다 첫번째. class Solution { public int findUnsortedSubarray(int[] nums) { int[] sortedArray = new int[nums.length]; sortedArray = nums.clone(); Arrays.sort(sortedArray); int startIndex = 0; int finishIndex = 0; boolean first = false; for(int i =0; i 2020. 8. 11.