목록전체 글 (122)
Ryureka
class Solution { public void rotate(int[] nums, int k) { int n = nums.length; int step = k % n; int[] temp = new int[n]; for(int i = 0; i
1. 내 풀이BruteForce - 시간 복잡도 O(N^2) 공간 복잡도 O(1) Time Limit Exceededclass Solution { public int maxProfit(int[] prices) { int n = prices.length; int ans = 0; for(int i = 0; i DP - 시간 복잡도 O(N) 공간 복잡도 O(N) 2ms오른쪽에 있는 가장 큰 숫자를 담아 dp 배열에 저장한다.최대 이익(maxP)는 dp[i]-prices[i] 중 가장 큰 값이 된다.class Solution { public int maxProfit(int[] prices) { int n = prices.length; int[] dp = new..
class Solution { public int removeDuplicates(int[] nums) { int idx = 0; int cnt = 1; for(int i = 0; i = 2이면 skip. if(cnt >= 2) continue; // cnt
class Solution { public int removeDuplicates(int[] nums) { // 시작인 0번째 원소는 넣고 1번째 부터 비교 int cnt = 1; for (int i = 0; i - 더 빠른 풀이class Solution { public int removeDuplicates(int[] nums) { int slow = 0; for(int fast = 1; fast
nums 배열의 원소 중에서 값이 val인 원소들을 제거 후 남은 원소들을 앞으로 밀착시키는 문제이다. nums 배열의 원소들을 nums2에 복사한다. 그리고 nums2의 원소들을 살펴보면서 값이 val이 아닌 원소만 nums 배열에 담아주었다.cnt 변수를 선언하고 하나씩 증가시켜 가면서 원소들을 앞으로 밀착시켜 주었다.class Solution { public int removeElement(int[] nums, int val) { int[] nums2 = new int[nums.length]; // nums 배열의 원소들을 nums2 배열로 복사 for(int i = 0; i
nums1 배열에 nums1에서 m개의 원소, nums2에서 n개의 원소를 오름차순으로 합치는 문제이다. nums3 배열을 선언하여 nums1 배열에서 정렬되어 있는 m개를 저장한다.그리고 nums1 배열의 m개를 모두 0으로 초기화 해준다. 그 후 idx1, idx2, idx3 세 개의 인덱스를 선언한다. 여기서 idx1은 nums1 배열의 인덱스를, idx2는 nums2 배열의 인덱스를, idx3는 nums3 배열의 인덱스를 의미한다. idx1 인덱스가 m + n보다 작은 동안 nums1에 nums2, nums3의 원소들을 비교하여 저장한다.idx3 인덱스가 m보다 크거나 같으면 nums3의 원소들이 모두 저장된 것이므로 nums2의 남은 원소들을 저장한다.idx2 인덱스가 n보다 크거나 같으면 nu..
import java.util.LinkedList;import java.util.Queue;import java.util.Scanner;public class Main { static int N,M; static int[][] map; static boolean[][] check; static int[][] dist; static int[] dx = {0,1,0,-1}; static int[] dy = {1,0,-1,0}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); M = sc.nextInt(); map = new int [N][M]; check = new boolea..
import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int t = 0; t = 0; i--) { if(isBreakAll) break; for(int j = M - 1; j >= 0; j--) { if(latte[i][j] == '#') { rightDownSharpPoint = new Point(i,j); isBreakAll = true; break; } } } isBreakAll = false; for..
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.util.HashSet;import java.util.StringTokenizer;public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new Buffer..
#include #include using namespace std;int main(){ ios::sync_with_stdio(0); cin.tie(0); int T; long long R, C, min, a; long long piramid, four_area; string s = ""; cin >> T; for (int t = 0; t > R >> C; min = R import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;impo..