力扣
class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
//排序后每次把最小的饼干发给胃口小的孩子
int i=0,j=0,count=0;
//有一个测试用例没饼干
if(s.length==0){
return 0;
}
while(true){
if(g[i]<=s[j]){
count++;
i++;
j++;
}else{
//最小的饼干不能满足最小的胃口
j++;
}
if(i>g.length-1||j>s.length-1){
break;
}
}
return count;
}
}
力扣
class Solution {
public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
List<List<Integer>> ans = new LinkedList<>();
List<Integer> way = new LinkedList<>();
way.add(0);
travl(graph,0,graph.length-1,way,ans);
return ans;
}
public void travl(int[][] graph,int start,int end,List<Integer> way,List<List<Integer>> ans){
if(start == end){
ans.add(way);
return ;
}
for(int val : graph[start]){
List<Integer> nextWay = new LinkedList<>(way);
nextWay.add(val);
travl(graph,val,end,nextWay,ans);
}
}
}