일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Where
- for문
- 재귀함수
- 배열
- MySQL
- 코딩테스트
- Algorithms
- node.js
- Developer_JoyKim
- array
- select
- join
- 코플릿
- array.slice()
- Hackerrank
- 개발자_조이킴
- 개발자의 책장
- 최강의 인생
- 블록체인
- 자바스크립트
- 알고리즘
- SQL
- array.push()
- 프로그래머스
- JavaScript
- 정규표현식
- Programmers
- 코드스테이츠
- 코딩공부
- 역행자
Archives
- Today
- Total
CodingSpace
[HackerRank/Algorithms] Strings - CamelCase 본문
Problem. Strings - CamelCase
Link.
https://www.hackerrank.com/challenges/camelcase/problem?isFullScreen=true
Description.
There is a sequence of words in CamelCase as a string of letters, s, having the following properties:
- It is a concatenation of one or more words consisting of English letters.
- All letters in the first word are lowercase.
- For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase.
Given s, determine the number of words in s.
Key Point.
My Answer.
'use strict';
const fs = require('fs');
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});
process.stdin.on('end', function() {
inputString = inputString.split('\n');
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the 'camelcase' function below.
*
* The function is expected to return an INTEGER.
* The function accepts STRING s as parameter.
*/
function camelcase(s) {
let cnt = 0;
for(let i = 0; i < s.length; i++) {
// 만약 i번째 문자가 대문자이면 cnt + 1
if(s[i] === s[i].toUpperCase())
cnt++;
}
return cnt + 1;
}
function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);
const s = readLine();
const result = camelcase(s);
ws.write(result + '\n');
ws.end();
}
References.
'HackerRank > Algorithm' 카테고리의 다른 글
[HackerRank/Algorithms] Sorting - Big Sorting (0) | 2022.09.10 |
---|---|
[HackerRank/Algorithms] Implementation - Equalize the Array (0) | 2022.09.08 |
[HackerRank/Algorithms] Implementation - Cut the sticks (0) | 2022.09.04 |
[HackerRank/Algorithms] Warmup - Compare the Triplets (0) | 2022.09.03 |
[HackerRank/Algorithms] Warmup - Staircase (0) | 2022.09.03 |
Comments