Where who wants to meet someone

뒤에서 5등 위로 본문

프로그래머스 알고리즘 문제 기록/코딩 기초 트레이닝

뒤에서 5등 위로

Lust3r 2024. 1. 30. 13:39
728x90

문제

https://school.programmers.co.kr/learn/courses/30/lessons/181852

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

내 답안 / 다른 사람들의 답안

import Foundation

func solution(_ num_list:[Int]) -> [Int] {
    return Array(num_list.sorted()[5...])
}

- num_list를 정렬한 상태에서 인덱스 5부터의 요소를 Array로 반환

 

// 풀이 1

import Foundation

func solution(_ num_list:[Int]) -> [Int] {
    return Array(num_list.sorted()[5...])
}

// 풀이 2

func solution(_ a:[Int]) -> [Int] {
    a.sorted()[5..<a.count].map{Int($0)}
}

 

 

점수: +1