검색결과 리스트
프로그래머스에 해당되는 글 199건
- 2023.02.24 프로그래머스 레벨1 대충 만든 자판 C#(Dictionary, ContainsKey)
- 2023.02.23 프로그래머스 레벨2 주식가격 C#(JAVA)
- 2023.02.11 프로그래머스 레벨2 C# 연속 부분 수열 합의 개수(Hash.Count, HashSet, Skip, Take, JAVA)
- 2023.02.11 프로그래머스 C# 행렬의 곱셈(3중 for문, JAVA)
- 2023.02.11 프로그래머스 레벨1 상위 n개 레코드(오라클SQL)
- 2023.02.11 프로그래머스 레벨3 자동차 대여 기록에서 대여중 / 대여 가능 여부 확인하기(오라클SQL, MAX, case when)
- 2023.02.11 프로그래머스 레벨4 입양 시각 구하기(2)(오라클SQL, 서브쿼리, CONNECT BY LEVEL)
- 2023.02.11 프로그래머스 레벨2 즐겨찾기가 가장 많은 식당 정보 출력하기(오라클SQL, IN)
글
프로그래머스 레벨1 대충 만든 자판 C#(Dictionary, ContainsKey)
C#
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(string[] keymap, string[] targets) {
int[] answer = new int[targets.Length];
Dictionary<char, int> dic = new Dictionary<char, int>();
for(int i=0;i<keymap.Length;i++)
{
for(int j=0;j<keymap[i].Length;j++)
{
if(dic.ContainsKey(keymap[i][j]) == false)
{
dic.Add(keymap[i][j], j+1);
//딕셔너리에 keymap에 있는 문자와 그에 따른 숫자를 저장해놓는다.
}
else
{
if(dic[keymap[i][j]] > j+1)
{
dic[keymap[i][j]] = j+1;
}
// 딕셔너리에 똑같은 게 있는데 숫자가 J+1보다 크면
//가장 숫자가 작았던 걸 딕셔너리에 저장한다.
}
}
}
for(int i=0;i<targets.Length;i++)
{
answer[i] = 0;
for(int j=0;j<targets[i].Length;j++)
{
if(dic.ContainsKey(targets[i][j]) == true)
{
answer[i] += dic[targets[i][j]];
}
else
{
answer[i] = -1;
break;
}
}
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 레벨1 문자열 나누기 C#(JAVA) (0) | 2023.02.24 |
---|---|
프로그래머스 레벨1 카드 뭉치 C#(JAVA) string 배열 (0) | 2023.02.24 |
프로그래머스 레벨2 피로도 C#(완전탐색) (0) | 2023.02.24 |
프로그래머스 이모티콘 할인행사 C#() (0) | 2023.02.23 |
프로그래머스 레벨3 가장 먼 노드 C#(JAVA) queue, BFS (0) | 2023.02.23 |
글
프로그래머스 레벨2 주식가격 C#(JAVA)
C#
using System;
public class Solution {
public int[] solution(int[] prices) {
int[] answer = new int[prices.Length];
int[] sample = prices;
for(int i = 0;i<prices.Length-1;i++)
{
for(int j = i+1;j<prices.Length;j++)
{
if(prices[i] <= prices[j])
{
answer[i]++;
}
else
{
answer[i]++;
break;
}
}
}
answer[prices.Length-1] = 0;
return answer;
}
}
//////////////////
using System;
using System.Collections.Generic;
public class Solution
{
public int[] solution(int[] prices)
{
Stack<int> stack = new Stack<int>();
int length = prices.Length;
List<int> answer = new List<int>(prices);
for (int i = 0; i < length; i++)
{
while (stack.Count != 0 && prices[stack.Peek()] > prices[i])
{
int top = stack.Pop();
answer[top] = i - top;
// 뒤에 있는 가격이 비교기준이 되는 가격보다 낮아질 경우에 대입하는 방법
}
stack.Push(i);
}
while (stack.Count != 0)
{
int top = stack.Pop();
answer[top] = length - 1 - top;
// 가격이 안 떨어졌을 때의 대입방법
}
return answer.ToArray();
}
}
//////////////////////
자바
import java.util.Stack;
class Solution {
public int[] solution(int[] prices) {
Stack<Integer> beginIdxs = new Stack<>();
int i=0;
int[] terms = new int[prices.length];
beginIdxs.push(i);
for (i=1; i<prices.length; i++)
{
while (!beginIdxs.empty() && prices[i] < prices[beginIdxs.peek()])
{
int beginIdx = beginIdxs.pop();
terms[beginIdx] = i - beginIdx;
}
beginIdxs.push(i);
}
while (!beginIdxs.empty())
{
int beginIdx = beginIdxs.pop();
terms[beginIdx] = i - beginIdx - 1;
}
return terms;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 레벨3 가장 먼 노드 C#(JAVA) queue, BFS (0) | 2023.02.23 |
---|---|
프로그래머스 레벨2 N-Queen C#(JAVA) - 완전탐색 private void/bool (0) | 2023.02.23 |
프로그래머스 레벨2 뒤에 있는 큰 수 찾기 C#(JAVA) peek, pop, push (0) | 2023.02.23 |
프로그래머스 레벨2 C# 연속 부분 수열 합의 개수(Hash.Count, HashSet, Skip, Take, JAVA) (0) | 2023.02.11 |
프로그래머스 C# 행렬의 곱셈(3중 for문, JAVA) (0) | 2023.02.11 |
글
프로그래머스 레벨2 C# 연속 부분 수열 합의 개수(Hash.Count, HashSet, Skip, Take, JAVA)
/// 내가 작성한 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public int solution(int[] elements) {
int[] doublearray = new int[2 * elements.Length];
/// 2배 길이의 배열을 작성해서 뒤에서 앞으로 합계를 구하는 경우가 가능하게 했다.
HashSet<int> hash = new HashSet<int>(); // 중복 저장이 불가능한 HashSet을 썼다.
for(int i = 0;i<2*elements.Length;i++)
{
doublearray[i] = elements[i%elements.Length];
}
/// 2배 배열을 대입
for(int i = 0;i<elements.Length;i++)
{
for(int j = 0;j<elements.Length;j++)
{
int[] newArray = doublearray.Skip(i).Take(j+1).ToArray();
hash.Add(newArray.Sum());
}
}
return hash.Count;
}
}
// 되기는 되는데 시간이 엄청나게 오래 걸려서 겨우겨우 실행이 됐다. 그래서 다른 분 코드를 참조한 것을 했다.
// skip부터 시작해서 take에 있는 숫자 만큼 취한다.
//
//
//
//
using System;
public class Solution {
public int solution(int[] elements)
{
int answer = 0;
int[] flagedInts = new int[elements.Length * 1000 + 1]; // 100만개까지 배열을 만든다. 길이가 1000이고, 배열에 들어가는 수가 1000까지니까 최대가 1000 * 1000 = 100만개까지 나온다. 전부 0이 들어가 있다.
for(int addingLen = 1; addingLen <= elements.Length; addingLen++)
{
for (int i = 0; i < elements.Length; i++)
{
int idx = 0;
for (int j = 0; j < addingLen; j++)
{
idx += elements[(i + j) % (elements.Length)];
}
// 선택된 배열 인덱스만 1을 집어넣게 해서 if문으로 중복을 걸러내고 answer의 값을 플러스 시켜서 갯수를 구한다.
if (flagedInts[idx] == 0)
{
flagedInts[idx] = 1;
answer++;
}
}
}
return answer;
}
}
// 이게 시간이 훨씬 덜 나온다.
자바
import java.util.*;
class Solution {
public int solution(int[] elements) {
Set<Integer> set = new HashSet<>();
int start = 1;
while(start < elements.length)
{
for (int i = 0; i < elements.length; i++)
{
int value = 0;
for (int j = i; j < i+start; j++)
{
value += elements[j%elements.length];
}
set.add(value);
}
start++;
}
int sum = 0;
for (int i = 0; i < elements.length; i++)
sum += elements[i];
set.add(sum);
return set.size();
}
}
import java.util.*;
class Solution {
public int solution(int[] elements) {
int answer = 0;
Set<Integer> set = new HashSet<>();
int start = 0;
for(int i=0; i<elements.length; i++)
{
int n = 1;
int idx = i;
int sum = 0;
while(n <= elements.length)
{
sum += elements[idx++];
set.add(sum);
if(idx >= elements.length)
idx = 0;
n++;
}
}
answer = set.size();
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 레벨2 주식가격 C#(JAVA) (0) | 2023.02.23 |
---|---|
프로그래머스 레벨2 뒤에 있는 큰 수 찾기 C#(JAVA) peek, pop, push (0) | 2023.02.23 |
프로그래머스 C# 행렬의 곱셈(3중 for문, JAVA) (0) | 2023.02.11 |
프로그래머스 C# 예상 대진표(JAVA) (0) | 2023.02.11 |
프로그래머스 문자열 내의 p와 y의 개수(JAVA, toLowerCase().split(""), equals) (0) | 2023.02.11 |
글
프로그래머스 C# 행렬의 곱셈(3중 for문, JAVA)
using System;
public class Solution {
public int[,] solution(int[,] arr1, int[,] arr2) {
int[,] answer = new int[arr1.GetLength(0),arr2.GetLength(1)];
for(int i = 0;i<arr1.GetLength(0);i++)
{
for(int j = 0;j<arr2.GetLength(0);j++)
{
for (int k = 0; k < arr2.GetLength(1); k++)
{
answer[i, k] += arr1[i, j] * arr2[j, k];
}
}
}
return answer;
}
}
자바
class ProductMatrix {
public int[][] productMatrix(int[][] A, int[][] B) {
int[][] answer = new int[A.length][B[0].length];
for(int i=0;i<answer.length;i++)
{
for(int j=0;j<answer[0].length;j++)
{
for(int k=0;k<A[0].length;k++)
{
answer[i][j]+=A[i][k]*B[k][j];
}
}
}
return answer;
}
public static void main(String[] args) {
ProductMatrix c = new ProductMatrix();
int[][] a = { { 1, 2 }, { 2, 3 } };
int[][] b = { { 3, 4 }, { 5, 6 } };
// 아래는 테스트로 출력해 보기 위한 코드입니다.
System.out.println("행렬의 곱셈 : " + c.productMatrix(a, b));
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 레벨2 뒤에 있는 큰 수 찾기 C#(JAVA) peek, pop, push (0) | 2023.02.23 |
---|---|
프로그래머스 레벨2 C# 연속 부분 수열 합의 개수(Hash.Count, HashSet, Skip, Take, JAVA) (0) | 2023.02.11 |
프로그래머스 C# 예상 대진표(JAVA) (0) | 2023.02.11 |
프로그래머스 문자열 내의 p와 y의 개수(JAVA, toLowerCase().split(""), equals) (0) | 2023.02.11 |
프로그래머스 JAVA 폰켓몬 (0) | 2023.02.09 |
글
프로그래머스 레벨1 상위 n개 레코드(오라클SQL)
-- 코드를 입력하세요
SELECT NAME
from (select *
from ANIMAL_INS
order by datetime)
where rownum < 2
'SQL프로그래밍' 카테고리의 다른 글
프로그래머스 레벨2 동명 동물 수 찾기(오라클SQL, group by, having) (0) | 2023.03.12 |
---|---|
프로그래머스 레벨1 이름이 있는 동물의 아이디(오라클SQL) (0) | 2023.03.12 |
프로그래머스 레벨3 자동차 대여 기록에서 대여중 / 대여 가능 여부 확인하기(오라클SQL, MAX, case when) (0) | 2023.02.11 |
프로그래머스 레벨4 입양 시각 구하기(2)(오라클SQL, 서브쿼리, CONNECT BY LEVEL) (0) | 2023.02.11 |
프로그래머스 레벨2 즐겨찾기가 가장 많은 식당 정보 출력하기(오라클SQL, IN) (0) | 2023.02.11 |
글
프로그래머스 레벨3 자동차 대여 기록에서 대여중 / 대여 가능 여부 확인하기(오라클SQL, MAX, case when)
-- 코드를 입력하세요
SELECT CAR_ID,
MAX(case when '2022-10-16' BETWEEN TO_CHAR(START_DATE, 'YYYY-MM-DD') and TO_CHAR(END_DATE, 'YYYY-MM-DD') then '대여중'
else '대여 가능'
end) as AVAILABILITY
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
group by CAR_ID
order by CAR_ID DESC;
--- 대여중의 Char가 대여 가능 보다 값이 크기 때문에 MAX로 하면 대여중이 하나라도 있으면 대여중 값이 튀어나오게 되도록 설계 되어 있다.
'SQL프로그래밍' 카테고리의 다른 글
프로그래머스 레벨1 이름이 있는 동물의 아이디(오라클SQL) (0) | 2023.03.12 |
---|---|
프로그래머스 레벨1 상위 n개 레코드(오라클SQL) (0) | 2023.02.11 |
프로그래머스 레벨4 입양 시각 구하기(2)(오라클SQL, 서브쿼리, CONNECT BY LEVEL) (0) | 2023.02.11 |
프로그래머스 레벨2 즐겨찾기가 가장 많은 식당 정보 출력하기(오라클SQL, IN) (0) | 2023.02.11 |
프로그래머스 레벨1 특정 옵션이 포함된 자동차 리스트 구하기(오라클SQL, like) (0) | 2023.02.11 |
글
프로그래머스 레벨4 입양 시각 구하기(2)(오라클SQL, 서브쿼리, CONNECT BY LEVEL)
-- 코드를 입력하세요
SELECT
l.hour,
nvl(count, 0) AS count
FROM (SELECT TO_CHAR(datetime, 'HH24') AS hour, count(*) AS count
FROM animal_outs
GROUP BY TO_CHAR(datetime, 'HH24')
ORDER BY hour) O,
(SELECT LEVEL-1 AS hour FROM dual CONNECT BY LEVEL<=24) L
WHERE L.hour = O.hour(+)
ORDER BY L.hour;
/// 몰라서 다른 분 거를 참고했다. 'HH24'는 알았는데 CONNECT BY LEVEL 이거는 몰랐다.
'SQL프로그래밍' 카테고리의 다른 글
프로그래머스 레벨1 상위 n개 레코드(오라클SQL) (0) | 2023.02.11 |
---|---|
프로그래머스 레벨3 자동차 대여 기록에서 대여중 / 대여 가능 여부 확인하기(오라클SQL, MAX, case when) (0) | 2023.02.11 |
프로그래머스 레벨2 즐겨찾기가 가장 많은 식당 정보 출력하기(오라클SQL, IN) (0) | 2023.02.11 |
프로그래머스 레벨1 특정 옵션이 포함된 자동차 리스트 구하기(오라클SQL, like) (0) | 2023.02.11 |
프로그래머스 레벨4 식품분류별 가장 비싼 식품의 정보 조회하기(오라클SQL, IN) (0) | 2023.02.09 |
글
프로그래머스 레벨2 즐겨찾기가 가장 많은 식당 정보 출력하기(오라클SQL, IN)
-- 코드를 입력하세요
SELECT FOOD_TYPE, REST_ID, REST_NAME, FAVORITES
from REST_INFO
where (FOOD_TYPE, FAVORITES) IN
(select FOOD_TYPE, MAX(FAVORITES)
from REST_INFO
group by FOOD_TYPE)
order by FOOD_TYPE DESC;
'SQL프로그래밍' 카테고리의 다른 글
프로그래머스 레벨3 자동차 대여 기록에서 대여중 / 대여 가능 여부 확인하기(오라클SQL, MAX, case when) (0) | 2023.02.11 |
---|---|
프로그래머스 레벨4 입양 시각 구하기(2)(오라클SQL, 서브쿼리, CONNECT BY LEVEL) (0) | 2023.02.11 |
프로그래머스 레벨1 특정 옵션이 포함된 자동차 리스트 구하기(오라클SQL, like) (0) | 2023.02.11 |
프로그래머스 레벨4 식품분류별 가장 비싼 식품의 정보 조회하기(오라클SQL, IN) (0) | 2023.02.09 |
프로그래머스 레벨1 자동차 대여 기록에서 장기/단기 대여 구분하기(오라클SQL, 날짜의 뺄셈, TO_CHAR) (0) | 2023.02.09 |