- 博客(10)
- 资源 (2)
- 收藏
- 关注
原创 反转字符串
package zql_jianzhi;public class Reverse { //StringBuffer/StringBuilder函数来翻转字符串 public static String reverse1(String str) { return new StringBuffer(str).reverse().toString(); }...
2019-07-30 17:50:56 118
原创 剑指offer-10
题目描述操作给定的二叉树,将其变换为源二叉树的镜像。代码public class Solution { public void Mirror(TreeNode root) { TreeNode temp=null; if(root!=null){ temp=root.right; root.rig...
2019-07-11 20:51:11 82
原创 剑指offer-8
题目描述输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)思路:1、首先设置标志位result = false,因为一旦匹配成功result就设为true,剩下的代码不会执行,如果匹配不成功,默认返回false2、递归思想,如果根节点相同则递归调用DoesTree1HaveTree2(),如果根节点不相同,则判断tree1的左子树和t...
2019-07-11 20:41:05 97
原创 剑指offer-7
题目描述我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?public class Solution { public int RectCover(int target) { if(target<=0) return 0; else...
2019-06-21 14:20:31 92
原创 剑指offer-6
题目描述(变态跳台阶)一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。public class Solution {public int JumpFloorII(int target) { if (target <= 0) { return -1; ...
2019-06-21 13:55:03 56
原创 剑指offer-5
题目描述一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果)。public class Solution { public int JumpFloor(int target) { int n1=1; int n2=2; int n3=0; if(targe...
2019-06-20 16:43:17 86
原创 剑指offer-4
题目描述大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0)。n<=39public class Solution { public int Fibonacci(int n) { int n1=0; int n2=1; int n3=0; if(n<=0)...
2019-06-20 16:01:21 86
原创 剑指offer-3
题目描述把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。import java.util.ArrayList;public class Solution { ...
2019-06-20 15:44:24 48
原创 剑指offer-2
题目描述在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。public class Solution { public boolean Find(int target, int [][] array) { int row=...
2019-06-20 11:36:00 112
原创 剑指offer-1
1、用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。package zql_jianzhi;import java.util.Stack;public class Solution { Stack<Integer> stack1=new Stack<Integer>(); Stack<Integer>...
2019-06-20 11:29:24 51
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人