145 二叉树的后续遍历
class Solution {
//后续遍历 先左,后右,再 根节点
List<Integer> res =new LinkedList<Integer>();
public List<Integer> postorderTraversal(TreeNode root) {
if(root==null) {
return res;
}
postorderTraversal(root.left);
postorderTraversal(root.right);
res.add(root.val);
return res;
}
}
523 连续子数和
/**
*
*/
/***
* @author 18071
* @Date 2019年3月5日
* 功能:给定一个包含非负数的数组和一个目标整数 k,
* 编写一个函数来判断该数组是否含有连续的子数组
* ,其大小至少为 2,总和为 k 的倍数,即总和为 n*k,其中 n 也是一个整数。
***/
public class test {
public static void main(String args[]) {
int [] x= {1,2,3};
int k=5;
Solution s =new Solution();
System.out.println(s.checkSubarraySum(x, k));
}
}
class Solution {
public boolean checkSubarraySum(int[] nums, int k) {//暴力法啊
int[] sum=new int[nums.length];
int summ=0;
for(int i=0;i<nums.length;i++) {
summ=nums[i];
for(int j=i+1;j<nums.length;j++) {
summ=summ+nums[j];
if(k != 0 && summ% k == 0)
{ return true;
}
else if(k == 0 && summ == k )
{
return true;
}
}
}
return false;
}
}