Algorithm (402) 썸네일형 리스트형 [프로그래머스] 두 정수의 합 - Math클래스 Level. 1 문제 풀이 class Solution { public long solution(int a, int b) { long answer = 0; int max = Math.max(a,b); int min = Math.min(a,b); for(int i = min; i (b - a + 1) * (a + b ) / 2 [프로그래머스] 문자열 내 마음대로 정렬하기 Level 1. 문제 풀이 import java.util.*; class Solution { public String[] solution(String[] strings, int n) { String[] answer = new String[strings.length]; for(int i=0; i [프로그래머스] 나누어 떨어지는 숫자 배열/ stream Level. 1 문제 풀이 import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { ArrayList list = new ArrayList(); for(int i=0; i i).toArray(); Arrays.sort(answer); return answer; } } list를 사용하여 정답을 구한 후, return타입에 맞추어 array로 변경해 주었다. ListArray -> Array list.stream().mapToInt(i -> i).toArray(); 다른 사람 풀이 import java.util.Arrays; class Solution { public int[] solution(int[] arr,.. [프로그래머스] 점프와 순간 이동 - 비트연산 Level.2 문제 풀이 #include using namespace std; int solution(int n) { int ans = 0; while(n>0){ if(n%2==0){ n/=2; } else { int num = n%2; ans += num; n -= num; } } return ans; } 다른 사람 풀이 1. #include using namespace std; int solution(int n) { int ans = 0; while(n >0) { ans += n%2; n /=2; } return ans; } 다른 사람 풀이 2. #include using namespace std; int solution(int n) { int ans=0; for(int i=0;i [프로그래머스] JadenCase 문자열 만들기 / isspace Level.2 문제 풀이 #include #include #include // isspace using namespace std; string solution(string s) { string answer = s; answer[0] = toupper(answer[0]); for(int i=1; i [프로그래머스] 행렬의 곱셈 Level.2 문제 풀이 #include #include using namespace std; vector solution(vector arr1, vector arr2) { vector answer; int Arow = arr1.size(); int Acol = arr1[0].size(); int Bcol = arr2[0].size(); for(int a=0; a [프로그래머스] 뒤에 있는 큰 수 찾기 - Stack 문제 풀이 #include #include #include using namespace std; // Stack // stack을 이용. 저장해놓고 비교하면서 끝나면 pop vector solution(vector numbers) { vector answer(numbers.size()); stack s; for(int i=0; i [프로그래머스] 줄 서는 방법 - 순열(DFS), DP 프로그래머스 - Level 2 문제 풀이 1. 깊이탐색 - 순열 (효율성 통과 X) #include #include using namespace std; vector visited; long long count = 0; string answer; //순열 void dfs(string s,int n, long long k){ if(s.size() == n){ count ++; if(count == k){ answer = s; } return; } for(int i=0; i 이전 1 ··· 37 38 39 40 41 42 43 ··· 51 다음