2018年11月9日
摘要: 【题目】 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is s 阅读全文
posted @ 2018-11-09 18:17 alau 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 【题目】 判断二叉树是否相同。 【思路】 check函数。 p==null并且q==null,返回true;(两边完全匹配) p==null或q==null,返回false;(p、q其中一方更短) p.val==q.val,值相同,继续迭代向左向右遍历check(p.left,q.left)&&ch 阅读全文
posted @ 2018-11-09 17:48 alau 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 【思路】 判断s是否为t的子串,所以length(s)<=length(t)。于是两个指针,一次循环。 将s、t转换为数组p1、p2。 i为过程中s的匹配长度。 i=0空串,单独讨论返回true。 当i=p1.length-1时返回true,否则循环结束返回false。 【代码】 【举例】 阅读全文
posted @ 2018-11-09 16:48 alau 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 【题目】 A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. 阅读全文
posted @ 2018-11-09 16:31 alau 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 简单 leetcode164 Maximum Gap sort两次 有参考 330 Patching Array 98 Validate Binary Search Tree BFS 60 Subsets II [done] 435 non-overlapping 455. Assign Cooki 阅读全文
posted @ 2018-11-09 16:10 alau 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 仅能操作一次时,需每次观察是否有为负情况置零。多次操作时,仅需判断是否后者大于前者。 leetcode 53、121、122 【代码】 class Solution { public int maxSubArray(int[] nums) { int sum=Integer.MIN_VALUE; i 阅读全文
posted @ 2018-11-09 08:35 alau 阅读(446) 评论(0) 推荐(0) 编辑
摘要: 【题目】 Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may c 阅读全文
posted @ 2018-11-09 08:26 alau 阅读(94) 评论(0) 推荐(0) 编辑