짝수는 싫어요
class Solution {
public int[] solution(int n) {
int[] answer = new int[(n+1)/2];
for (int i = 1; i <= n; i++) {
if (i % 2 != 0) {
answer[i/2] = i;
}
}
return answer;
}
}
- 다른 풀이
import java.util.stream.IntStream; class Solution { public int[] solution(int n) { return IntStream.rangeClosed(0, n).filter(value -> value % 2 == 1).toArray(); } }
import java.util.List; import java.util.ArrayList; class Solution { public int[] solution(int n) { List<Integer> answer = new ArrayList<>(); for(int i=1; i<=n; i++){ if(i % 2 == 1){ answer.add(i); } } return answer.stream().mapToInt(x -> x).toArray(); } }
import java.util.*; class Solution { public ArrayList solution(int n) { ArrayList<Integer> answer = new ArrayList<Integer>(); for(int i=1; i<=n; i++){ if(i%2 != 0) { answer.add(i); } } return answer; } }
stream 사용 방식은 아직도 잘 모르겠구먼,,
def solution(n):
answer = [i for i in range(1, n+1) if i % 2 ==1]
return answer
- 다른 풀이
def solution(n): return [i for i in range(1, n+1, 2)]
제약조건
create table member
( mem_id char(8) not null primary key,
mem_name varchar(10) not null,
height tinyint unsigned null
);
혹은
create table member
( mem_id char(8) not null primary key,
mem_name varchar(10) not null,
height tinyint unsigned null
);
alter table member add constraint primary key (mem_id);
create table buy
( num int auto_increment not null primary key,
mem_id char(8) not null,
prod_name char(6) not null,
foreign key(mem_id) references member(mem_id)
);
- member 테이블에서 mem_id(PK) 를 변경하거나, member를 삭제하면?
-> 일대다 (PK-FK) 관계를 맺은 상태에서는 제약조건으로 오류를 발생 시킴- 해결 방법 : on update cascade, on delete cascade를 입력해주면 참조 테이블의 데이터도 같이 변경, 삭제해줌
create table buy ( num int auto_increment not null primary key, mem_id char(8) not null, prod_name char(6) not null, foreign key(mem_id) references member(mem_id) on update cascade on delete cascade );
drop table buy, member; -- 실습을 위해 테이블 모두 삭제
create table member
( mem_id char(8) not null primary key,
mem_name varchar(10) not null,
email char(30) null unique,
height tinyint unsigned null check (height >= 100),
phone1 char(3) default '02'
);
오버로딩
한 클래스 내에 같은 이름의 메서드를 여러 개 정의하는 것
조건
오버라이딩
부모클래스로부터 상속받은 메서드의 내용을 변경하는 것
조건
다형성