Algorithm/Java

Algorithm/Java

프로그래머스 - 최댓값과 최솟값

https://school.programmers.co.kr/learn/courses/30/lessons/12939 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public String solution(String s) { String[] temp=s.split(" "); int[] mm = new int[2]; //min, max for(int i=0;ix) mm[0]=x; else if(mm[1]

Algorithm/Java

프로그래머스 - 콜라츠 추측

https://school.programmers.co.kr/learn/courses/30/lessons/12943 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 테스트케이스 3번에서 계속 답이 다르게 나와서(-1이라고 나와야되는데 488번만에 통과된걸로 뜸) 찾아봤더니 num이 int형이라 연산을 계속하다보니 오버플로우돼서 그렇다고 한다! 그래서 long으로 바꾼 변수로 진행했더니 잘 돌아가더라.. class Solution { public int solution(int num) { int answer = 0; long x=(long)num; while(..

Algorithm/Java

프로그래머스 - 서울에서 김서방 찾기

https://school.programmers.co.kr/learn/courses/30/lessons/12919 class Solution { public String solution(String[] seoul) { String answer="김서방은 "; for(int i=0;i

Algorithm/Java

프로그래머스 - 모의고사

https://school.programmers.co.kr/learn/courses/30/lessons/42840 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 마지막에 리턴할 때 list에 있는 값을 일일히 int[] 형의 answer에 저장하여 반환하는 것이 아닌, list를 array로 변환하며 바로 return하고 싶었다. List 클래스의 toArray함수를 정확히 알기 위해 다음의 블로그들을 참고하였다. http://asuraiv.blogspot.com/2015/06/java-list-toarray.html https://hianna.tisto..

Algorithm/Java

프로그래머스 - 3진법 뒤집기

https://school.programmers.co.kr/learn/courses/30/lessons/68935 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 걍 무식하게 Stack 써서 풀엇음...... flag를 쓴 이유: 앞에 0있으면 지워야돼서, 한 번이라도 0 아닌 수 나오면 그 뒤 0은 실제 수 취급, 그 전엔 없는 수 취급 import java.util.*; class Solution { public int solution(int n) { int answer = 0; Stack stack = new Stack(); while(n>0){ st..

Algorithm/Java

프로그래머스 - 로또의 최고 순위와 최저 순위

https://school.programmers.co.kr/learn/courses/30/lessons/77484 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int[] solution(int[] lottos, int[] win_nums) { int[] answer =new int[2]; int count=0; //현재 보이는 것 중 맞는거 int zeros=0; //0 카운트 for(int i=0;i

Algorithm/Java

프로그래머스 lv2- 124 나라의 숫자

https://school.programmers.co.kr/learn/courses/30/lessons/12899 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 숫자가 1,2,4로 나타낼 수밖에 없다는 것에서 착안함! 3으로 나누는데, 여기서는 0,1,2까지의 수로 표현하는 게 아닌 1,2,4로 표현하기 때문에 3진수에서의 0 상태를? 조정해주는게 중요했다. 그래서 3으로 나누기 전에 --n하고 여기서 0은 1, 1은 2, 2는 4로 변환되도록 했다. 설명하려니 이상한데, 아래 그림을 보면 이해할 수 있을 것이다. import java.util.*; cl..

Algorithm/Java

프로그래머스 lv1- 문자열 내 p와 y의 개수

https://school.programmers.co.kr/learn/courses/30/lessons/12916 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr find 가능한지 모르겠어서;; 걍 for문으로 다 돌렸다.(다른 분들 답 보니 안 되는듯!) class Solution { boolean solution(String s) { s=s.toLowerCase(); char x; int pCount=0, yCount=0; for (int i=0;i

Algorithm/Java

프로그래머스 lv1 - 음양 더하기

https://school.programmers.co.kr/learn/courses/30/lessons/76501 class Solution { public int solution(int[] absolutes, boolean[] signs) { int answer = 0; for(int i=0;i

Algorithm/Java

프로그래머스 lv1- 내적

https://school.programmers.co.kr/learn/courses/30/lessons/70128 class Solution { public int solution(int[] a, int[] b) { int answer = 0; for(int i=0;i

yoursin
'Algorithm/Java' 카테고리의 글 목록 (13 Page)