https://leetcode.com/problems/container-with-most-water/ class Solution { public int maxArea(int[] height) { int ww=0; int templeft=0, tempright=height.length-1; while(templeftww){ ww=x;} if (height[tempright]
https://leetcode.com/problems/reverse-integer/submissions/ class Solution { public int reverse(int x) { boolean minus = false; long ans=0; if(x0){ int temp=x%10; x/=10; ans=ans*10+temp; } if (ans Integer.MAX_VALUE) return 0; return (minus)? (int)-ans: (int)ans; } }
https://leetcode.com/problems/zigzag-conversion/submissions/ class Solution { public String convert(String s, int numRows) { int group=(numRows-2)*2+2; if(numRows
https://school.programmers.co.kr/learn/courses/30/lessons/87390 class Solution { public int[] solution(int n, long left, long right) { int[] answer = new int[(int)(right-left+1)]; int t,j; for(int k=0;k+left
https://school.programmers.co.kr/learn/courses/30/lessons/12914 사실상 피보나치와 같음 dfs로 풀었을 때 시간 초과돼서 피보나치와 같이 반복문 활용함! class Solution {//dfs - 시간 초과 long answer=0; public void dfsJump(int left){ if (left==0){answer++; return;} else if(left==1){ answer++; return;} else{ dfsJump(left-1); dfsJump(left-2); } } public long solution(int n) { dfsJump(n); return answer%1234567; } } 테스트케이스 1번만 오류가 계속 났는데, n=1..
https://school.programmers.co.kr/learn/courses/30/lessons/12981 이미 쓴 단어는 hashset에 저장 이전 단어의 맨뒷글자와 지금 단어의 맨 앞 글자가 동일한지 체크 기본이 0,0이라, 루프를 break없이 끝까지 다 돌면 그게 반환됨 break 걸리기 직전에 그 값을 저장해줌 import java.util.*; class Solution { public int[] solution(int n, String[] words) { int[] answer = new int[2]; //탈락자 번호, round Set wordList = new HashSet(); String lastWord=""; int k; for(k=0;k
https://school.programmers.co.kr/learn/courses/30/lessons/12945 //재귀함수로 푼 방법 ->시간초과 class Solution { public int fib(int a){ if(a==1) return 1; else if(a==0) return 0; else return fib(a-1)+fib(a-2); } public int solution(int n) { return fib(n)%1234567; } } //반복문 사용 class Solution { public int solution(int n) { int[] arr = new int[n+1]; arr[0]=0; arr[1]=1; for(int a=2;a
https://school.programmers.co.kr/learn/courses/30/lessons/12941 작은 값과 큰 값을 곱하는 게 최솟값을 만드는 데 키 import java.util.Arrays; class Solution { public int solution(int []A, int []B) { int answer = 0; Arrays.sort(A); Arrays.sort(B); int len=A.length; for(int i=0;i
https://school.programmers.co.kr/learn/courses/30/lessons/17680 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.*; //deque를 사용해서, 사이즈가 cacheSize 넘으면 제일 아래 것 삭제! class Solution { public int solution(int cacheSize, String[] cities) { int answer = 0; Deque queue = new ArrayDeque(); for(int i=0;icacheSize) { queue.remove..