Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- codewars
- 유닉스의탄생
- maxlinelength
- 규칙없음
- conf
- Algorithm
- vscode
- printer_helper
- 코로나백신
- organizeImports
- opensouce
- 글쓰기가필요하지않은인생은없다
- pep8
- goalng
- 독후감
- 오큘러스퀘스트2
- ProxyServer
- httppretty
- GlobalInterprintLock
- springboot
- python
- flake8
- 조엘온소프트웨어
- codewar
- Golang
- typevar
- pyenv
- restfulapi
- loadimpact
- Lint
Archives
- Today
- Total
일상적 이야기들.
codewars: Counting Duplicates 본문
문제
- https://www.codewars.com/kata/counting-duplicates
Codewars: Train your coding skills
Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.
www.codewars.com
문제풀이
- 입력된 문자열에서, 중복된 char가 몇개 있는지 체크하는 프로그램입니다.
- 그렇기에, a~z까지의 배열을 생성하고, 문자열을 순회하면서 해당 문자가 몇번 나왔는지 확인을 하게 됩니다.
- 그 이후에, 지금까지 나온 갯수를 판단하여 1개 이상이 나왔다면, resultCnt를 올려주어 return 시켜주게 됩니다.
public class CountingDuplicates {
public static int duplicateCount(String text) {
// Write your code here
int []ary = new int[26];
int resultCnt = 0;
for(int i=0; i<text.length(); ++i) {
char c = text.charAt(i);
if('a' <= c && c <= 'z') {
ary[c-'a']++;
}else if('A' <= c && c <= 'Z') {
ary[c-'A']++;
}
}
for(int i=0; i<26; ++i) {
if(ary[i] > 1) {
resultCnt++;
}
}
return resultCnt;
}
}
'프로그래밍 > 알고리즘 문제풀이' 카테고리의 다른 글
codewar: Find the odd int (0) | 2019.07.16 |
---|---|
codewar: Sum of Parts (0) | 2019.07.02 |
codewar: Convert a String to Number! (0) | 2019.07.02 |
codewar: Where is THB? (0) | 2019.07.02 |
codewar: Remove First and Last Character (0) | 2019.06.25 |
Comments