- 博客(30)
- 收藏
- 关注
原创 翻转字符串
/** * Created by lxw, [email protected] on 2017/10/31. * 翻转字符串 */public class reverseString { public void rotateWord(char[] chas){ if(chas == null || chas.length == 0){ re
2017-10-31 22:29:12 105
原创 在有序但含有空的数组中查找字符串
/** * Created by lxw, [email protected] on 2017/10/31. * 在有序但含有空的数组中查找字符串 */public class findString { public int getIndex(String[] strs, String str){ if(strs == null || strs.length ==
2017-10-31 20:50:50 121
原创 判断字符数组中是否所有的字符都出现一次
/** * Created by lxw, [email protected] on 2017/10/31. * 判断字符数组中是否所有的字符都出现一次 * 实现时间复杂度为O(N)的方法 * 在保证空间复杂度为O(1)的前提下,时间复杂度尽可能低 */public class stringIsUnique { public boolean isUnique1(char[]
2017-10-31 20:09:10 300
原创 给定一个字符串str,返回str的统计字符串
/** * Created by lxw, [email protected] on 2017/10/31. * 给定一个字符串str,返回str的统计字符串 */public class countString { public String getCountString(String str){ if(str == null || str.equals("")
2017-10-31 18:56:35 1698
原创 替换字符串中连续出现的指定字符串
/** * Created by lxw, [email protected] on 2017/10/31. * 替换字符串中连续出现的指定字符串 */public class replaceString { public String replace(String str, String from, String to){ if(str == null || fr
2017-10-31 16:48:28 140
原创 将数字字符串转化成整数值
/** * Created by lxw, [email protected] on 2017/10/31. * 将数字字符串转化成整数值 */public class strToInt { public static boolean isValid(char[] arr){ if(arr[0] != '-' && (arr[0] '9')){
2017-10-31 15:34:23 1369
原创 去掉字符串中连续出现的K个0的子串
/** * Created by lxw, [email protected] on 2017/10/31. * 去掉字符串中连续出现的K个0的子串 */public class KZeros { public static void main(String[] args){ String str1 = "A00B"; int k1 = 2;
2017-10-31 10:45:24 213
原创 字符串中数字子串的求和
/** * Created by lxw, [email protected] on 2017/10/31. * 字符串中数字子串的求和 */public class StringNumSum { public static void main(String[] args){ String str1 = "A1CD2E33"; String str
2017-10-31 10:13:00 626
原创 二叉树节点间的最大距离问题
/** * Created by lxw, [email protected] on 2017/10/30. * 二叉树节点间的最大距离问题 */public class BTMaxDistance { public class Node{ int value; Node left; Node right; pub
2017-10-30 22:32:05 169
原创 二叉树中找到两个节点的最近公共祖先
import java.util.HashMap;import java.util.HashSet;/** * Created by lxw, [email protected] on 2017/10/30. * 二叉树中找到两个节点的最近公共祖先 */public class CommonAncestor { public class Node{ int
2017-10-30 21:45:33 1243
原创 在含有父结点指针的二叉树中找到一个结点的后继结点
/** * Created by lxw, [email protected] on 2017/10/30. * 在二叉树中找到一个结点的后继结点 * 后继结点为中序遍历中的下一个结点 */public class SuccessorNode { public class Node{ public int value; public No
2017-10-30 20:35:51 474
原创 递归和非递归的方式实现二叉树的先序、中序和后序遍历
import java.util.Stack;/** * Created by lxw, [email protected] on 2017/10/30. * */public class PreOrder_InOrder_PosOrder { public class Node{ public int value; public Node
2017-10-30 19:51:23 299
原创 判断t1树中是否有与t2树拓扑结构完全相同的子树
/** * Created by lxw, [email protected] on 2017/10/30. * 判断t1树中是否有与t2树拓扑结构完全相同的子树 */public class IsContainSubTree { public class Node{ public int value; public Node left;
2017-10-30 15:38:24 704
原创 二叉树的序列化和反序列化
import java.util.LinkedList;import java.util.Queue;/** * Created by lxw, [email protected] on 2017/10/30. * 二叉树的序列化和反序列化 * 序列化可以基于先序、中序、后序、按层 的二叉树遍历方式来进行修改 */public class SerBinaryTree {
2017-10-30 14:41:11 152
原创 判断t1树是否包含t2树全部相同的拓扑结构
/** * Created by lxw, [email protected] on 2017/10/30. */public class T1ContainsT2 { public static class Node{ public int value; public Node left; public Node right;
2017-10-30 11:02:21 291
原创 调整搜索二叉树中两个错误结点
import java.util.Stack;/** * Created by lxw, [email protected] on 2017/10/29. * 调整搜索二叉树中两个错误结点,找到这两个错误结点并在 * 结构上完全交换两个节点的位置 */public class TwoErrNode { public class Node{ int value
2017-10-30 10:29:10 275
原创 "之"字形打印矩阵
/** * Created by lxw, [email protected] on 2017/10/29. * "之"字形打印矩阵 */public class ZigZagMatrix { public void printZigZagMatrix(int[][] matrix){ int tR = 0; int tC = 0;
2017-10-29 09:37:42 209
原创 二叉树的按层打印和ZigZag打印
import java.util.Deque;import java.util.LinkedList;import java.util.Queue;/** * Created by lxw, [email protected] on 2017/10/28. * 二叉树的按层打印,使用一个队列 两个变量 * 二叉树的ZigZag打印,使用一个双端队列 LinkedList */pub
2017-10-28 11:08:45 290
原创 两个单链表(可能有环)是否相交,若相交则返回第一个相交点
/** * Created by lxw, [email protected] on 2017/10/27. * 两个单链表是否相交,若相交则返回第一个相交点(单链表可能有环) */public class IntersectNode { public class Node{ public int value; public Node next;
2017-10-27 23:20:26 271
原创 删除链表的中间结点
/** * Created by lxw, [email protected] on 2017/10/27. * 若删除一链表的某一节点,需要找到该节点对应的前一个结点, * 故删除链表的中间节点是找到该链表中间结点的变形,使用快 * 慢指针找到中间结点的前一个节点 */public class RemoveMidNode { public class Node{
2017-10-27 20:51:22 225
原创 删除单链表的倒数第K个节点
/** * Created by lxw, [email protected] on 2017/10/27. * 删除单链表中倒数第K个结点 */public class TheLastKthNode { public class Node{ public int value; public Node next; p
2017-10-27 19:15:49 1651
原创 合并两个有序的单链表
/** * Created by lxw, [email protected] on 2017/10/27. * 合并两个有序的单链表 */public class MergeSortedList { public class Node{ public int value; public Node next; pub
2017-10-27 16:52:46 134
原创 无序数组中找到一个局部最小的位置
/** * Created by lxw, [email protected] on 2017/10/27. * 在无序数组中二分查找找到局部最小值的位置 */public class LocMinPos { public int getLocMinPos(int[] arr){ if(arr == null || arr.length ==0)
2017-10-27 15:43:17 420
原创 给定等概率随机产生1~M的随机函数, 实现等概率随机产生1~N的随机函数
/** * Created by lxw, [email protected] on 2017/10/27. * 给定一个等概率随机产生1~M的随机函数,实现等概率随机产生1~N的随机函数 */public class RandomConvert { public int rand1ToM(int m){ return (int) (Math.random()*m
2017-10-27 15:19:55 844
原创 字典序全排列
/** * Created by lxw, [email protected] on 2017/10/26. * 1,从右端开始扫描,若出现前一个比后一个小,记录前一个的元素下表index *2,再找出index以后比该元素大的中的最小值的下标 minIndex *3,交换arr[index],arr[minIndex] *4,index以后的元素实现反转 * 结束条件:前一个都比后一
2017-10-26 22:25:00 199
原创 子数组的最大累加和问题
/** * Created by lxw, [email protected] on 2017/10/26. */public class MaxSum { public int maxSum(int[] arr){ if(arr == null || arr.length ==0) return 0; int max = In
2017-10-26 18:13:29 253
原创 直观地打印二叉树
/** * Created by lxw, [email protected] on 2017/10/26. */public class PrintBinaryTree { public static class Node{ public int value; public Node left; public Node right;
2017-10-26 15:28:52 253
原创 构造数组的MaxTree
import java.util.HashMap;import java.util.Stack;/** * Created by lxw, [email protected] on 2017/10/26. */public class MaxTree { public class Node{ public int value; public N
2017-10-26 13:51:59 220
原创 将搜索二叉树转换成双向链表
/** * Created by lxw, [email protected] on 2017/10/25. */public class convert { class Node{ public int value; public Node left; public Node right; public Node(i
2017-10-26 09:41:26 119
原创 两个有序数组相加和的topK问题
import java.util.HashSet;/** * Created by lxw, [email protected] on 2017/10/24. */public class topKSum { public static void main(String[] args){ int[] arr1 = {1,2,3,4,5}; int[...
2017-10-25 10:44:09 1640 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人