답안 :
class Solution {
public int[] solution(String s) {
int[] answer = new int[2];
int cnt = 0;
int zeroCnt = 0;
while (!s.equals("1")) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '0') {
zeroCnt++;
}
}
s = s.replace("0", "");
s = Integer.toBinaryString(s.length());
cnt++;
}
answer[0] = cnt;
answer[1] = zeroCnt;
return answer;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution s = new Solution();
String s1 = "110010101001";
System.out.println(s.solution(s1));
}
}
답안 :
class Solution {
public int solution(long n) {
int answer = 0;
int f0 = 0;
int f1 = 1;
int f2 = 1;
for(int i=1; i<n; i++){
f2 = (f0 + f1) % 1234567;
f0 = f1;
f1 = f2;
}
answer = f2;
return (int) answer;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution s = new Solution();
int n = 3;
System.out.println(s.solution(n));
}
}
N%1234567 의 값을 구하기 위해 계산단위마다 나눠줌.틀린답안 :
class Solution {
public int solution(int n) {
if (n <= 1)
return n;
else
return (solution(n - 1) + solution(n - 2))%1234567;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Solution s = new Solution();
int n = 3;
System.out.println(s.solution(n));
}
}
틀린답안 보단 특성상 불가능에 가까운 답안이 맞는거같음.
- 직원중 보너스가 1,000
미만인 이름과 보너스 액수를 출력
답안 :
select e1.name, b1.bonus
from Employee e1
left join Bonus b1
on e1.empId = b1.empId
where b1.bonus < 1000 or b1.bonus is null
- 해당 학생이 과목에대해 시험에 몇번 참석했는지에대해 출력
답안 :
select s1.student_id , s1.student_name ,s2.subject_name, count(e1.subject_name) as 'attended_exams'
from Students s1
cross join Subjects s2
left join Examinations e1
on e1.subject_name = s2.subject_name and s1.student_id = e1.student_id
group by 1,2,3
order by 1,3
보지 않은 학생도 포함해야기에 CROSS JOIN을 사용.