본문 바로가기

Algorithm

(171)
[Prefix Sum(Product)] 238. Product of Array Except Self 문제 바로가기 배열이 주어졌을 때 본인(nums[i])을 제외한 나머지 원소들의 곱을 구하는 문제입니다. 배열 원소를 모두 곱하고 각 자리에 있는 애로 나누면 되겠다 싶었는데 그러지 말랍니다. 문제에서 요구하는 접근법이 따로 있나 봅니다. Java class Solution { public int[] productExceptSelf(int[] nums) { int n = nums.length; int[] answer = new int[n]; // prefix int prefixProduct = 1; for (int i = 0; i < n; i++) { answer[i] = prefixProduct; prefixProduct *= nums[i]; } // suffix int suffixProduct = 1..
[Greedy/우선순위 큐] 1642. Furthest Building You Can Reach 문제 바로가기 Furthest Building You Can Reach - LeetCode Can you solve this real interview question? Furthest Building You Can Reach - You are given an integer array heights representing the heights of buildings, some bricks, and some ladders. You start your journey from building 0 and move to the next building leetcode.com 미디엄 문제긴 한데 꽤 간단합니다. 빌딩을 타 넘어야 되는데요, 벽돌과 사다리의 개수를 고려해서 최대한 많이 타 넘어가야 합니다. 우선순위 ..
[Dijkstra] 1514. Path with Maximum Probability 문제 바로가기 Path with Maximum Probability - LeetCode Can you solve this real interview question? Path with Maximum Probability - You are given an undirected weighted graph of n nodes (0-indexed), represented by an edge list where edges[i] = [a, b] is an undirected edge connecting the nodes a and b wi leetcode.com 오랜만에 미듐 문제를 건드려 보았습니다. 우째 푸는지 몰라서 멋쟁이 형님의 유튭 강의를 보고 풀었습니다.^^~ 요 문제.. 재밌네용. 오랜만에 다익스트라 알..
[배열/시뮬레이션] 59. Spiral Matrix II 문제 바로가기 Spiral Matrix II - LeetCode Can you solve this real interview question? Spiral Matrix II - Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Example 1: [https://assets.leetcode.com/uploads/2020/11/13/spiraln.jpg] Input: n = 3 O leetcode.com 54번 문제의 친구입니다. 얘는 반대로 n 이 주어졌을 때 n x n 크기의 2차원 배열을 만들어주면 됩니다. 시곗방향으로 삥삥 돌면서요. 이딴게 미디움??????????..
[배열/시뮬레이션] 54. Spiral Matrix 문제 바로가기 Spiral Matrix - LeetCode Can you solve this real interview question? Spiral Matrix - Given an m x n matrix, return all elements of the matrix in spiral order. Example 1: [https://assets.leetcode.com/uploads/2020/11/13/spiral1.jpg] Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Outpu leetcode.com 어제의 추천 문제입니다. 보다 더 머리를 쓰는 문제를 풀어야 실력이 향상될텐데... 퇴근하고 오면 머리쓰기가 왜이리 싫은지~~ 2차원 배열이 주어지면 걔를 시계방향으로 삥삥 안..
[DP] 64. Minimum Path Sum - Java 문제 바로가기 Minimum Path Sum - LeetCode Can you solve this real interview question? Minimum Path Sum - Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or rig leetcode.com 오늘의 추천 문제입니다. 맨위에 하나씩 뜨는게 추천 문제가 맞나?? 암튼 매일 바뀌는 거기에 뜬 문제입니다. m x n 크기의 2차원 배열이 주어지고 왼쪽 맨 위(g..
[Summer/Winter Coding(~2018)][누적합] 쿠키 구입 - Java 문제 바로가기 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 프로그래머스 레벨4짜리 문제입니다. 효율성도 있어서 짜증나는 문제인데요, 레벨 4 정도는 아닌듯...????????? public int solution(int[] cookie) { int answer = 0; // 누적합 int[] sum = new int[cookie.length + 1]; sum[0] = 0; sum[1] = cookie[0]; for (int i = 2; i rightSum) { left++; } else { right--; } } return 0; } 기본적인 아이디어는..
[투 포인터] 905. Sort Array By Parity - Java 오랜만입니다. 릿코드에 있는 Algorithm1 플랜은 이틀만에 때려치웠습니다. 왜냐면 귀찮기 때문에 그래도 틈틈이 심심할 때마다 한 두 문제씩 풀긴 했었습니다. 정리를 안해서 그렇지 그래서 오랜만에 한 문제 풀고 끄적여 보려 합니다. Easy 문제로다가 ㅎ 문제 바로가기 Sort Array By Parity - 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 오늘 푼 문제는 이 문제입니다. 릿코드에서 Problems 들어가면 오른쪽에 달력이 있는데, 맨날 한 문..