面试题
liyinan11
这个作者很懒,什么都没留下…
展开
-
15、链表中倒数第k个节点
/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode FindKthToTail(ListNode head,int原创 2017-07-30 14:18:48 · 108 阅读 · 0 评论 -
16、反转链表(递归方法)
/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode ReverseList(ListNode head) {原创 2017-07-30 14:57:00 · 185 阅读 · 0 评论 -
17、合并两个排序链表
/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode Merge(ListNode list1,ListNode l原创 2017-07-30 15:04:59 · 134 阅读 · 0 评论 -
18、数的子结构
牛客约定空树不是任意一个树的子结构,很讨厌/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public cla原创 2017-07-30 16:39:26 · 138 阅读 · 0 评论 -
19、二叉树的镜像
越来越喜欢递归了!/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }}*/public class Solution原创 2017-07-30 17:03:02 · 152 阅读 · 0 评论 -
20、顺时针打印矩阵
LeetCode原题54,复习一遍import java.util.ArrayList;public class Solution { public ArrayList printMatrix(int [][] matrix) { ArrayList ret = new ArrayList<>(); if(matrix == null || matri原创 2017-07-30 17:42:11 · 149 阅读 · 0 评论 -
21、包含min函数的栈
没看懂要干啥的一道题???黑人问号???import java.util.Stack;public class Solution { Stack stack = new Stack<>(); Stack stack_min = new Stack<>(); public void push(int node) { stack.push(node);原创 2017-07-30 18:27:31 · 145 阅读 · 0 评论 -
23、从上往下打印二叉树
LeetCode简化版import java.util.ArrayList;import java.util.*;/**public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { t原创 2017-07-30 20:35:07 · 165 阅读 · 0 评论 -
13、在O(1)时间删除链表节点
package test;class ListNode{ int val; ListNode next; public ListNode(int x){ val = x; }}public class Solution { public ListNode deleteNode(ListNode head, ListNode target){ if(head == null)原创 2017-07-29 17:29:13 · 149 阅读 · 0 评论 -
12、打印1到最大的n位数
package offerCome;public class Solution{ public void printOneToMax(int n){ if(n<1) return; char[] num=new char[n]; back(num,n,0); return; } public void back(char[] num,int n,int level){原创 2017-02-25 21:51:42 · 150 阅读 · 0 评论 -
3、二维数组的查找
public class Solution{ public boolean find(int[][] matrix,int target){ if(matrix.length==0||matrix[0].length==0) return false; int row=matrix.length; int col=matrix[0].length; int i=0,j=col-1原创 2017-01-08 14:50:17 · 199 阅读 · 0 评论 -
5、从尾到头打印链表
import java.util.*;public class Solution{ public void PrintReverseList(ListNode head){ if(head==null) return; Stack stack=new Stack<>(); ListNode p=head; while(p!=null){ stack.push(p);原创 2017-01-08 20:13:31 · 123 阅读 · 0 评论 -
6、重建二叉树
public class Solution{ public BinaryTreeNode ConstructBinaryTree(int[] preorder,int[] inorder){ BinaryTreeNode root=new BinaryTreeNode(); if(preorder.length==0) return root; return Construct(pr原创 2017-01-08 21:39:18 · 117 阅读 · 0 评论 -
7、用两个栈实现队列
import java.util.*;public class Solution{ public void appendTail(Stack s,int a){ s.push(a); } public void deleteHead(Stack s){ if(s.isEmpty()){ System.out.println("queue is empty"); retu原创 2017-01-09 11:43:43 · 130 阅读 · 0 评论 -
8、旋转数组的最小数字
public class Solution{ public int rotateMin(int[] arr){ if(arr.length<=0) return -1; if(arr.length==1) return arr[0]; int start=0,end=arr.length-1; while(start<end){ if(end-start==1)return原创 2017-01-09 15:42:22 · 138 阅读 · 0 评论 -
9、斐波那契数列
public class Solution{ public long Fibonacci(int n){ if(n==0) return 0; if(n==1) return 1; long ret=0; long first=0,second=1; for(int i=2;i<=n;i++){ ret=first+second; first=second;原创 2017-01-09 19:57:09 · 222 阅读 · 0 评论 -
10、二进制中1的个数
public class Solution{ public long NumberOfOne(int n){ int ret=0; while(n!=0){ ret++; n=(n-1)&n; } return ret; } public static void main(String args[]){ int n=7; Solution sl=new S原创 2017-01-09 20:29:28 · 129 阅读 · 0 评论 -
11、数值的整数次方
public class Solution{ public double Power(double base,int exp){ if(exp==0) return 1; if(exp==1) return base; if(exp<0){ base=1/base; exp=Math.abs(exp); } double ret=Power(base,exp>>1原创 2017-01-09 20:54:22 · 195 阅读 · 0 评论 -
22、栈的压入、弹出序列
import java.util.ArrayList;import java.util.*;public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { Stack stack = new Stack<>(); int j = 0; for(in原创 2017-07-30 20:22:39 · 164 阅读 · 0 评论