上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 28 下一页
摘要: 题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 题目解答 import java.util.Stack; public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); //压 阅读全文
posted @ 2018-12-14 15:59 chan_ai_chao 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。 题目解答 /** * Definition for 阅读全文
posted @ 2018-12-14 15:14 chan_ai_chao 阅读(90) 评论(0) 推荐(0) 编辑
摘要: 题目描述 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList。 题目解答 方法一: /** * public class ListNode { * int val; * ListNode next = null; * * ListNode(int val) { * this.val = 阅读全文
posted @ 2018-12-14 11:20 chan_ai_chao 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 题目描述 请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 题目解答 public class Solution { public String replaceSpace(StringBuf 阅读全文
posted @ 2018-12-14 10:58 chan_ai_chao 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 题目解答 public class Solution { public boolean Find 阅读全文
posted @ 2018-12-14 10:56 chan_ai_chao 阅读(146) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public static void sortStackByStack(Stack stack){ Stack help=new Stack(); while(!stack.isEmpty()){ int cur=stack.pop(); while(!help... 阅读全文
posted @ 2018-09-28 08:55 chan_ai_chao 阅读(144) 评论(0) 推荐(0) 编辑
摘要: public class Pet { private String type; public Pet(String type){ this.type=type; } public String getPetType(){ return this.type; } } public class Dog extends Pe... 阅读全文
posted @ 2018-09-27 11:11 chan_ai_chao 阅读(128) 评论(0) 推荐(0) 编辑
摘要: public class ReverseStack { public static int getAndRemoveLastElement(Stack stack){ int result=stack.pop(); if(stack.isEmpty()){ return result; }else{ ... 阅读全文
posted @ 2018-09-27 09:22 chan_ai_chao 阅读(97) 评论(0) 推荐(0) 编辑
摘要: class MyQueue { private Stack stackPush; private Stack stackPop; /** Initialize your data structure here. */ public MyQueue() { this.stackPush=new Stack(); this.stack... 阅读全文
posted @ 2018-09-26 12:57 chan_ai_chao 阅读(131) 评论(0) 推荐(0) 编辑
摘要: class MinStack { private Stack stackData; private Stack stackMin; /** initialize your data structure here. */ public MinStack() { this.stackData=new Stack(); thi... 阅读全文
posted @ 2018-09-26 11:14 chan_ai_chao 阅读(1268) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 28 下一页