-
12. H-Index코딩 테스트/Level 2 2020. 7. 26. 23:27반응형
https://programmers.co.kr/learn/courses/30/lessons/42747
파이썬
def solution(citations): for i, v in enumerate(sorted(citations, reverse=True)): if i >= v: return i return i + 1
자바스크립트
function solution(citations) { citations.sort((a, b)=>b-a); let n = 0 while (n < citations.length && citations[n] > n) n++ return n; }
자바
import java.util.Arrays; class Solution { public int solution(int[] citations) { Arrays.sort(citations); for (int i = 0; i < citations.length; i++) if (citations[citations.length - i - 1] <= i) return i; return citations.length; } }
코틀린
import java.util.Arrays; class Solution { fun solution(citations: IntArray): Int { Arrays.sort(citations) for (i in citations.indices) if (citations[citations.size - i - 1] <= i) return i return citations.size } }
C#
using System; public class Solution { public int solution(int[] citations) { Array.Sort(citations); for (int i = 0; i < citations.Length; i++) if (citations[citations.Length - i - 1] <= i) return i; return citations.Length; } }
GO
import "sort" func solution(citations []int) int { sort.Sort(sort.Reverse(sort.IntSlice(citations))) for i, v := range citations { if i >= v { return i } } return len(citations) }
반응형