-
[LeetCode] 1492. The kth Factor of nLeetCode 2021. 10. 21. 22:39728x90
https://leetcode.com/problems/the-kth-factor-of-n/
The kth Factor of n - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
The kth Factor of n - Medium


왜 Medium인지 모르겠는 문제다..
1부터 n까지 for문을 돌리며 그 수를 n으로 나눴을때 나머지가 0이라면 count를 ++해준다.
count 가 k가 될떄 리턴.
없을 경우 -1 리턴.
전체 풀이 코드
class Solution { public: int kthFactor(int n, int k) { for (int i=1, s=0; i<=n; i++) { if (n%i==0) s++; if (s==k) return i; } return -1; } };'LeetCode' 카테고리의 다른 글
[LeetCode] 6. ZigZag Conversion (0) 2021.10.22 [LeetCode] 451. Sort Characters By Frequency (0) 2021.10.22 [LeetCode] 844. Backspace String Compare (0) 2021.10.21 [LeetCode] 289. Game of Life (0) 2021.10.21 [LeetCode] 381. Insert Delete GetRandom O(1) - Duplicates allowed (0) 2021.10.21