Skip to content

Merge Level2 before all problems solved. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 7, 2022
148 changes: 148 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

# Created by https://www.toptal.com/developers/gitignore/api/macos,webstorm
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,webstorm


.idea/*


### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride


# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### WebStorm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### WebStorm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# End of https://www.toptal.com/developers/gitignore/api/macos,webstorm
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -19,9 +19,9 @@

## Level 1 ✅

풀이 완료(2022년 1월)


- 전체 문제 수: 54문제
- 풀이 문제 수: 54문제
- 풀이 완료 시점: 2022년 1월

## Level 2 👨🏻‍💻(풀이 중..)

29 changes: 29 additions & 0 deletions level-2/124-나라의-숫자.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1
function solution(n) {
var answer = '';
const oneTwoFour = ['4','1','2']
while (n>0){
const remainder = n % 3
answer = oneTwoFour[remainder] + answer;
n = Math.floor((n-1)/3) //나누어떨어지지 않을 때에도 -1해도 상관없음
}
return answer;
}

//정답 2
function solution(n) {
var answer = '';
const oneTwoFour = ['4','1','2']
while (n>0){
const remainder = n % 3
answer = oneTwoFour[remainder] + answer;
if(remainder === 0){
n = Math.floor((n-1)/3)
}else{
n = Math.floor(n/3)
}
}
return answer;
}
24 changes: 24 additions & 0 deletions level-2/H-Index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1
function solution(citations) {
var answer = 0;
citations.sort((a,b)=>b-a)
let h = 0
while(h+1<=citations[h]) h++
answer = h
return answer;
}

//정답 2
function solution(citations) {
var answer = 0;
let h = 0
let length = 0
while(length >= h){
h++
length = citations.filter(citation => citation>=h).length
}
answer = h - 1
return answer;
}
8 changes: 8 additions & 0 deletions level-2/JadenCase-문자열-만들기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
function solution(s) {
var answer = ''
answer = s.split(' ').map(word=> word.charAt(0).toUpperCase() + word.substring(1).toLowerCase()).join(' ')
//word[0]은 빈 문자열을 만나면 undefined를, word.charAt(0)은 빈 문자열을 만나면 빈 문자열을 반환한다.
return answer;
}
18 changes: 18 additions & 0 deletions level-2/N개의-최소공배수.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
function solution(arr) {
var answer = 0;
answer = arr.reduce((a,b)=> leastCommonMultiple(a,b), 1)
return answer;
}
function leastCommonMultiple(a, b){
return a * b / greatestCommonDivisor(a, b)
}
function greatestCommonDivisor(a, b){
while(b > 0){
let r = a % b;
a = b;
b = r;
}
return a;
}
20 changes: 20 additions & 0 deletions level-2/[1차]-캐시.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
function solution(cacheSize, cities) {
var answer = 0;
let cache = []
if (cacheSize === 0) return 5 * cities.length
for (const city of cities) {
const cityLC = city.toLowerCase()
if (cache.includes(cityLC)) {
cache.splice(cache.indexOf(cityLC), 1)
cache.unshift(cityLC)
answer += 1
} else {
if (cache.length >= cacheSize) cache.pop()
cache.unshift(cityLC)
answer += 5
}
}
return answer;
}
14 changes: 14 additions & 0 deletions level-2/가장-큰-수.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
function solution(numbers) {
var answer = '';
numbers.sort(sortFunc)
answer = numbers.join('')
if(answer[0] === '0') return '0'
return answer;
}
const sortFunc = (a,b) =>{
const compareA = parseInt(a.toString() + b.toString())
const compareB = parseInt(b.toString() + a.toString())
return compareB - compareA
}
63 changes: 63 additions & 0 deletions level-2/괄호-변환.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
//정답 1
function solution(p) {
if(p.length === 0) return p
let bracketCount = 0
let isURight = true
for(let i=0; i<p.length; i++){
bracketCount = p[i] === '(' ? bracketCount + 1 : bracketCount - 1
if(bracketCount < 0) isURight = false
if(bracketCount === 0){
const [u, v] = [p.slice(0,i+1), p.slice(i+1)]
if(isURight){
return u + solution(v)
}else{
let emptyString = '(' + solution(v) + ')'
const slicedReversedString = u
.slice(1,u.length-1)
.split('')
.map(bracket=> bracket === '(' ? ')' : '(')
.join('')
return emptyString + slicedReversedString
}
}
}
}

//정답 2
function solution(p) {
if(p.length === 0){
return p
}else{
const sliceIndex = balancedIndex(p)
const [u, v] = [p.slice(0,sliceIndex+1), p.slice(sliceIndex+1)]
if(isRight(u)){
return u + solution(v)
}else{
let emptyString = '(' + solution(v) + ')'
const slicedReversedString = u
.slice(1,u.length-1)
.split('')
.map(bracket=> bracket === '(' ? ')' : '(')
.join('')
return emptyString + slicedReversedString
}
}
}
const isRight = (str) => {
if(str[0] === ')') return false
let stack = 0
for(let i=0; i<str.length; i++){
stack = str[i] === '(' ? stack + 1 : stack - 1
if(stack < 0) return false
}
return stack === 0
}
const balancedIndex = (str) =>{
let count = 0
for(let i=0; i<str.length; i++){
count = str[i] === '(' ? count + 1 : count - 1
if(count === 0) return i
}
}
36 changes: 36 additions & 0 deletions level-2/괄호-회전하기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//https://github.com/codeisneverodd/programmers-coding-test
//완벽한 정답이 아닙니다.
function solution(s) {
let answer = 0;
let sArr = s.split('')
if(isRight(sArr.join(''))) answer += 1
for(let i=0; i<sArr.length - 1; i++){
sArr.push(sArr.shift())
if(isRight(sArr.join(''))) answer += 1
}
return answer;
}
function isRight(str){
const bracketOpen = ['[', '{', '('], bracketClose = [']', '}', ')']
let status = [{open: false, openOrder: []}, {open: false, openOrder: []}, {open: false, openOrder: []}]
for(let sIndex=0; sIndex<str.length; sIndex++){
for(let bIndex = 0; bIndex<3; bIndex++){
if(str[sIndex] === bracketOpen[bIndex]){
status[bIndex].open = true
status[bIndex].openOrder.push(sIndex)
}
if(str[sIndex] === bracketClose[bIndex]){
if(status[bIndex].openOrder.length > 0){
if(status.filter(check=>check.open && check.openOrder[check.openOrder.length - 1] > status[bIndex].openOrder[status[bIndex].openOrder.length - 1]).length > 0)
return false //먼저 닫혀야 하는 괄호보다 먼저 닫힘
status[bIndex].openOrder.pop()
status[bIndex].open = false
}else{
return false //열리기 전에 닫힘
}
}
}
}
for(let i=0; i<3; i++) if(status[i].open) return false //닫히지 않은 괄호가 있음
return true
}
Loading
Oops, something went wrong.