Numbers can be regarded as product of its factors. For example,
8 = 2 x 2 x 2; = 2 x 4.
Write a function that takes an integer n and return all possible combinations of its factors.
Note:
You may assume that n is always positive.
Factors should be greater than 1 and less than n.
Java Solution
public List<List<Integer>> getFactors(int n) { List<List<Integer>> result = new ArrayList<List<Integer>>(); List<Integer> list = new ArrayList<Integer>(); helper(2, 1, n, result, list); return result; } public void helper(int start, int product, int n, List<List<Integer>> result, List<Integer> curr){ if(start>n || product > n ) return ; if(product==n) { ArrayList<Integer> t = new ArrayList<Integer>(curr); result.add(t); return; } for(int i=start; i<n; i++){ if(i*product>n) break; if(n%i==0){ curr.add(i); helper(i, i*product, n, result, curr); curr.remove(curr.size()-1); } } } |
Nice Guide About Java. This Is The Best Basic Tutorial And Appreciate It.
Very interesting blog. Thanks a lot for sharing such a good source with all, i appreciate your efforts taken for the same. digital marketing company in bangalore
Thank for giving article and you present this article so precisely that it can be understand properly.
Fantastic article. This item offers an exceptional Java solution to the factor combinations on LeetCode problem. We appreciate ProgramCreek sharing this useful and well-written code. Anyone wishing to improve their problem-solving abilities should definitely use it. Continue your amazing work.
Best SEO Services In Hyderabad
https://betopseo.com/
Thanks for sharing.
Best SEO Company in Bangalore.
https://skyaltum.com
Thanks for sharing.
Best Digital marketing company in Bangalore
Thanks for sharing.
web development company in hyderabad
nice information
Video production company in Delhi
Interesting
Video Production Company In Bangalore
Nice post is any other alternate way available https://brandstory.in/digital/video-production/
Wow it is really wonderful and awesome thus it is very much useful
https://www.avatarstudios.in/video-production-company-in-bangalore
When I initially commented, I clicked the “Notify me when new comments are added†checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.
https://www.besanttechnologies.com/training-courses/cloud-computing-training/amazon-web-services-training-institute-in-chennai
http://www.besanttech.com/aws-training-in-chennai.php
only n/2 iterations should be needed in for loop `for(int i=start; i<n; i++)`