일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Spring Data JDBC
- spring data jpa
- 컬렉션프레임워크
- 첫글자대문자
- 인텔리제이
- 그리디
- 알고리즘
- Publishing
- 거듭제곱
- 백준알고리즘
- CLI명령어
- 스프링
- HTML
- java
- 자바
- 페어프로그래밍
- 백엔드
- 계산기만들기
- 회고
- 데일리코딩
- 제네릭스
- CSS
- 자료구조
- testing
- Spring Security
- FilterChain
- fibonacci
- 깃허브
- 문자열뒤집기
- 부트캠프
Archives
- Today
- Total
나의 모양
[DailyCoding] 24 | isSubsetOf 본문
✏️ Description
Return whether the sample is a subset of the base by receiving two arrays
- input
- base: temporary Array with element of int
- sample: temporary Array with element of int
- output: boolean
- caution: no duplicates
- example of in/output
int[] base = new int[]{1, 2, 3, 4, 5};
int[] sample = new int[]{1, 3};
boolean output = isSubsetOf(base, sample);
System.out.println(output); // --> true
sample = new int[]{6, 7};
output = isSubsetOf(base, sample);
System.out.println(output); // --> false
base = new int[]{10, 99, 123, 7};
sample = new int[]{11, 100, 99, 123};
output = isSubsetOf(base, sample);
System.out.println(output); // --> false
📝 Flow
1. get one by one
1-1. from sample to sampleArr
1-2. from base to baseArr
2. if it matches then
- change the flag to false and navigate to the next sampleArr
3. if doesn't matches then
- flag is true => return false
4. if get no return false => return true
📚 TIL
- Implement Array instead List.contains method of List
- flag
👩🏻💻 Implementation
for (int intSample : sample) {
boolean flag = true;
for (int intBase : base) {
if (intSample == intBase) {
flag = false;
break;
}
}
if (flag) return false;
}
return true;
'SEB > Daily Coding' 카테고리의 다른 글
[DailyCoding] 25 | power (0) | 2022.08.26 |
---|---|
[DailyCoding] 21 | largestProductOfThree (0) | 2022.08.22 |
[DailyCoding] 17 | computeSquareRoot (0) | 2022.08.12 |
[DailyCoding] 16 | isIsogram (0) | 2022.08.11 |
[DailyCoding] 08 | convertDoubleSpaceToSingle (0) | 2022.08.01 |
Comments