145 二叉树的后续遍历 && 523. 连续的子数组和

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;
        
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值