forked from rbmonster/learning-note
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
148 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 评论系统设计 | ||
|
||
[如何设计评论系统](https://zhuanlan.zhihu.com/p/455199524) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 核酸系统 | ||
[假如我是核酸系统架构师](https://mp.weixin.qq.com/s/s2Q0qVYzB6oIz2VoVmnR8A) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
System.out.println(solution(5)); | ||
} | ||
|
||
private static int solution(int N) { | ||
if(N> 45) { | ||
return -1; | ||
} | ||
if (N>=0 && N<=9) { | ||
return N; | ||
} | ||
List<Integer> combineList = new LinkedList<>(); | ||
for(int i = 1;i<=9;i++) { | ||
int start = i; | ||
int target = N; | ||
List<Integer> combine = new LinkedList<>(); | ||
while(target>0 && start<=9) { | ||
combine.add(start); | ||
target-=start; | ||
if(target<0 || target<i) { | ||
break; | ||
} | ||
if (target>start && target<=9) { | ||
combine.add(target); | ||
combineList.add(combine.size()); | ||
combine.remove(combine.size()-1); | ||
} | ||
start++; | ||
} | ||
} | ||
int res = 0; | ||
for(Integer tmp : combineList) { | ||
res+= countCombine(tmp); | ||
} | ||
return res; | ||
} | ||
|
||
private static int countCombine(int n) { | ||
int res = 1; | ||
while(n>0) { | ||
res *=n; | ||
n--; | ||
} | ||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.