Skip to content
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

26-alstjr7437 #196

Merged
merged 3 commits into from
May 25, 2024
Merged

26-alstjr7437 #196

merged 3 commits into from
May 25, 2024

Conversation

alstjr7437
Copy link
Member

@alstjr7437 alstjr7437 commented May 22, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

H-Index

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

20๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

์˜ˆ์ œ์™€ ๊ฐ™์ด
[3, 0, 6, 1, 5] ์ด ์™”๋‹ค๊ณ  ๊ฐ€์ •ํ•˜๋ฉด




์•„๋ž˜์™€ ๊ฐ™์ด
[6, 5, 3, 1, 0]์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ์„ ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.



๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ํ‘œ๋ฅผ ์ด์šฉํ•ด์„œ ํ™•์ธํ•ด๋ณด๋ฉด

๊ฐœ์ˆ˜ ์ธ์šฉ ์ˆ˜ ํ™•์ธ
1 6 6 > 1ย  (X)
2 5 5 > 2ย  (X)
3 3 3 = 3ย  (O) - ์ตœ๋Œ“๊ฐ’
4 1 1 < 4ย  (O)
5 0 0 < 5 (O)

์œ„์™€ ๊ฐ™์ด ์ง„ํ–‰์„ ํ•˜๊ฒŒ ๋˜์–ด์„œ
๊ฐ ์ธ์šฉ์ˆ˜๊ฐ€ ์ œ์ผ ํฐ ์ตœ๋Œ“๊ฐ’์ด ๋ ๋•Œ
1 < 4๋Š” ๋” ์ž‘์•„์ง€๋ฏ€๋กœ X


์œ„์˜ ์˜ˆ์ œ์—์„œ๋Š” 3์ด ๋ฉ๋‹ˆ๋‹ค.




์‚ฌ์‹ค ์ฒ˜์Œ์—๋Š” ๋ฌธ์ œ ์ดํ•ด๋ฅผ ์ •ํ™•ํžˆ ๋˜์ง€ ์•Š์•„์„œ ์ธํ„ฐ๋„ท์— ์•ฝ๊ฐ„์”ฉ ๊ฒ€์ƒ‰์„ ํ•ด๋ณด๋‹ˆ ์ •๋ ฌ์„ ํ•˜๊ณ  ์ธ์šฉ์ˆ˜์™€ ์ตœ๋Œ€๋ฅผ ๋น„๊ตํ•˜๋ฉฐ ํ•˜๋Š” ๋ถ€๋ถ„์ด๋”๊ตฐ์š”.



๋ฌธ์ œ๋ฅผ ์ดํ•ดํ•˜๋‹ˆ๊นŒ ์ฝ”๋“œ๋Š” ๊ธˆ๋ฐฉ ์‰ฝ๊ฒŒ ๋‚˜์™”์Šต๋‹ˆ๋‹ค..
์ƒ๊ฐ๋ณด๋‹ค ๋„ˆ๋ฌด ์‰ฌ์›Œ์„œ ๋‚œ์ด๋„ ์กฐ์ ˆ์— ์‹คํŒจํ•ด๋ฒ„๋ฆฐ..

def solution(citations):
    citations.sort(reverse=True)  
    
    for i in range(len(citations)):
        if(citations[i] < i+1):    
            return i
        
    return len(citations) 

๊ทธ๋ฆฌ๊ณ  ์ฒ˜์Œ์—๋Š” len(citations)๋ฅผ ์•ˆํ•˜๊ฒŒ ๋˜์—ˆ๋Š”๋ฐ
4,4,4,4๊ฐ€ ๋“ค์–ด์˜ค๊ฒŒ ๋˜๋ฉด 4๊ฐ€ ๋˜์•ผํ•˜๋Š”๋ฐ
i๋ฅผ ์ €์žฅํ•ด๋‘๊ณ  return i๋ฅผ ํ•˜๊ฒŒ ๋˜๋‹ˆ๊นŒ
0์ด ๋‚˜์˜ค๊ฒŒ ๋์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

๋ฌธ์ œ๋ฅผ ์ž˜ ์ดํ•ดํ•˜๋Š”๊ฒŒ ์ •๋ง ์ค‘์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐ๋“ญ๋‹ˆ๋‹ค..

Copy link
Collaborator

@SeongHoonC SeongHoonC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜ธ๋‹ค๋‹ฅ ๋น ๋ฅด๊ฒŒ ํ’€์—ˆ๋Š”๋ฐ ๋ฑ์œผ๋กœ ํ‘ธ์…จ๊ตฐ์š”?
์•„.. ์•„๋‹ˆ๋„ค์š”ใ…‹ใ…‹

class Solution {
    fun solution(citations: IntArray): Int {
        val sortedCitations = citations.sortedDescending()
        var max = 0
        for(i in sortedCitations.indices) {
            if(sortedCitations[i]>= i+1){
                max = i+1
            } 
        }
        return max
    }
}

Copy link

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์‚ฌ์‹ค ์ด ๋ฌธ์ œ์˜ ์ตœ๋Œ€ ์ ์€ ๋ฌธ์ œ ์ดํ•ด๋ž€ ๋ง์ด์ฃ ...
์žฌ๋ฐŒ๋Š” ๊ฒŒ, ์ด์ง„ํƒ์ƒ‰์œผ๋กœ๋„ ํ’€ ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค :)

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<int> citations) {
    int begin = 0, end = 10000;
    int answer = 0;
    while(begin <= end) {
        int mid = (begin + end) / 2;
        
        int count = 0;
        for(const auto& citation : citations) {
            if(citation >= mid)
                count++;
        }
        
        if(count >= mid) {
            answer = mid;
            begin = mid + 1;
        } else {
            end = mid - 1;
        }
    }
    
    return answer;
}

@alstjr7437
Copy link
Member Author

alstjr7437 commented May 23, 2024

์‚ฌ์‹ค ์ด ๋ฌธ์ œ์˜ ์ตœ๋Œ€ ์ ์€ ๋ฌธ์ œ ์ดํ•ด๋ž€ ๋ง์ด์ฃ ... ์žฌ๋ฐŒ๋Š” ๊ฒŒ, ์ด์ง„ํƒ์ƒ‰์œผ๋กœ๋„ ํ’€ ์ˆ˜ ์žˆ๋‹ต๋‹ˆ๋‹ค :)

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<int> citations) {
    int begin = 0, end = 10000;
    int answer = 0;
    while(begin <= end) {
        int mid = (begin + end) / 2;
        
        int count = 0;
        for(const auto& citation : citations) {
            if(citation >= mid)
                count++;
        }
        
        if(count >= mid) {
            answer = mid;
            begin = mid + 1;
        } else {
            end = mid - 1;
        }
    }
    
    return answer;
}

๋งž์Šต๋‹ˆ๋‹ค.... ๋ฌธ์ œ ์ดํ•ด๋ฅผ ํ•˜๋‹ˆ๊นŒ ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€ ๋ฐ”๋กœ ๋‚˜์˜ค๋”๋ผ๊ตฌ์š”!!

๊ทผ๋ฐ ๋ฌธ์ œ ์ดํ•ด๊ฐ€ ์•ˆ๋˜์„œ ์ธํ„ฐ๋„ท์„ ์ฐธ๊ณ ํ•ด๋ฒ„๋ฆฐ;;

์ด์ง„ํƒ์ƒ‰์œผ๋กœ๋„ ํ’€๋ฆฌ๋Š”๊ตฐ์š”
๋‹ค๋ฅธ์‚ฌ๋žŒ ํ’€์ด ๋ณด๋‹ˆ๊นŒ ์ด๋ ‡๊ฒŒ ๊ฐ„๋‹จํ•˜๊ฒŒ 2์ค„๋กœ๋งŒ ์ถœ๋ ฅ์ด ๋˜๋Š”๊ฒŒ ์‹ ๊ธฐํ–ˆ์Šต๋‹ˆ๋‹ค!

def solution(citations):     
    citations.sort(reverse=True)     
    answer = max(map(min, enumerate(citations, start=1)))     
    return answer

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™€ ์˜ˆ์ „์— ํ‘ผ ์ฝ”๋“œ์ธ๋ฐ,

์ง„์งœ ๋ฐ”๋ณด ๊ฐ™์ด ํ’€์—ˆ์—ˆ๋„ค์š”..

def solution(citations):
    citations.sort(reverse=True)
    count=0
    for h in range(0,1001):
        for j in citations:
            if h<=j:
                count+=1
        if h<=count:
            answer = h
        count=0
    return answer

์™€ ์˜ˆ์ „์— ์ง  ์ฝ”๋“œ์ธ๋ฐ ์ง„์งœ ๋ฐ”๋ณด๊ฐ™์ด ํ‘ธ๋ ใ…†๋„ค์š”....

๋‚œ์ด๋„ ์กฐ์ ˆ ์‹คํŒจ ใ…‡ใ…ˆ์ž…๋‹ˆ๋‹ค~ ์™„๋นค์น˜ ๋งž์œผ์„ธ์š”~

Comment on lines +1 to +8
def solution(citations):
citations.sort(reverse=True)

for i in range(len(citations)):
if(citations[i] < i+1):
return i

return len(citations)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™€ ์ฝ”๋“œ 5์ค„ ๋ชจ์ž„์š”

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3์ค„๋กœ ๋งŒ๋“  ๋ณ€ํƒœ๋“ค์ด ์žˆ๋Š”๊ฑฐ ๋ณด๊ณ  ์•„์ง ๋ถ€์กฑํ•˜๋‹ค๊ณ  ๋Š๊ผˆ์Šต๋‹ˆ๋‹ค....

Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ •๋ ฌ์„ reverseํ•˜๋Š”๊ฒŒ ํ•ต์‹ฌ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ท

์ „ ์ฒ˜์Œ์— ์ •๋ ฌ์„ reverseํ•œ๋‹ค๋Š” ๊ฑธ ์ƒ๊ฐ์„ ๋ชปํ•ด์„œ len(citations)/2๋ฅผ ๊ธฐ์ค€์œผ๋กœ h-index ๊ตฌ๋ถ„ํ•˜๊ณ  .. ๋บ‘๋บ‘ ๋‘˜๋Ÿฌ๊ฐ”๋„ค์š”

์ˆ˜๊ณ ํ•˜์…จ์Šด๋‹ค-!

def solution(citations):
    answer = 0
    
    citations.sort(reverse = True)
    
    for i in citations:
        if answer < i:
            answer += 1
        else:
            break
    
    
    return answer

@alstjr7437
Copy link
Member Author

์ •๋ ฌ์„ reverseํ•˜๋Š”๊ฒŒ ํ•ต์‹ฌ์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ท

์ „ ์ฒ˜์Œ์— ์ •๋ ฌ์„ reverseํ•œ๋‹ค๋Š” ๊ฑธ ์ƒ๊ฐ์„ ๋ชปํ•ด์„œ len(citations)/2๋ฅผ ๊ธฐ์ค€์œผ๋กœ h-index ๊ตฌ๋ถ„ํ•˜๊ณ  .. ๋บ‘๋บ‘ ๋‘˜๋Ÿฌ๊ฐ”๋„ค์š”

์ˆ˜๊ณ ํ•˜์…จ์Šด๋‹ค-!

def solution(citations):
    answer = 0
    
    citations.sort(reverse = True)
    
    for i in citations:
        if answer < i:
            answer += 1
        else:
            break
    
    
    return answer

์–ด ๋งž์Šต๋‹ˆ๋‹ค!! reverse๋ฅผ ํ•˜์ง€ ์•Š๊ณ  ํ’€ ์ˆ˜๋Š” ์žˆ๋Š”๋ฐ ์•ˆํ•˜๊ฒŒ ๋˜๋ฉด
๋”ฐ๋กœ ๊ณ„์‚ฐ์„ ๋„ฃ์–ด๋‘ฌ์•ผํ•˜๋Š”๊ฒŒ ๋„ˆ๋ฌด ๊ท€์ฐฎ๋”๋ผ๊ตฌ์š”!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants