2020年9月6日
摘要: package my; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class MergeIntervals { int[][] merge(int[][] intervals) 阅读全文
posted @ 2020-09-06 15:08 凌晨三点半的飞机 阅读(185) 评论(0) 推荐(0) 编辑
  2020年8月29日
摘要: 判断字符串是否是IP package my; public class BooleanIP { boolean isIpLegal(String string){ if(string ==null ||string.length() < 7 || string.length() > 15){ ret 阅读全文
posted @ 2020-08-29 14:36 凌晨三点半的飞机 阅读(294) 评论(1) 推荐(0) 编辑
  2020年8月26日
摘要: 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。 示例 1: 输入: "babad"输出: "bab"注意: "aba" 也是一个有效答案。示例 2: 输入: "cbbd"输出: "bb" package my; public class LongestPal 阅读全文
posted @ 2020-08-26 01:25 凌晨三点半的飞机 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 给定一个未排序的整数数组,找出最长连续序列的长度。 要求算法的时间复杂度为 O(n)。 示例: 输入: [100, 4, 200, 1, 3, 2]输出: 4解释: 最长连续序列是 [1, 2, 3, 4]。它的长度为 4。 package my; import java.util.Arrays; 阅读全文
posted @ 2020-08-26 00:32 凌晨三点半的飞机 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成。给定的字符串只含有小写英文字母,并且长度不超过10000。 示例 1: 输入: "abab" 输出: True 解释: 可由子字符串 "ab" 重复两次构成。示例 2: 输入: "aba" 输出: False示例 3: 输入: "abc 阅读全文
posted @ 2020-08-26 00:14 凌晨三点半的飞机 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 示例 1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。示例 2: 输入: "bbbbb"输出: 1解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。示例 3: 阅读全文
posted @ 2020-08-26 00:04 凌晨三点半的飞机 阅读(131) 评论(0) 推荐(0) 编辑
  2020年8月24日
摘要: 数组反转: public class ArrayDemo { public static void main(String[] args){ int[] arrays = {1,2,3,4,5,6}; String[] arrays2 ={"I","LOVE","YOU"}; arrays2=rev 阅读全文
posted @ 2020-08-24 00:19 凌晨三点半的飞机 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 冒泡排序: public class MaoPaoSort { public static int[] maopaoSort(int[] nums){ boolean hasChange = true; for(int i= 0; i<nums.length-1 && hasChange ;i++) 阅读全文
posted @ 2020-08-24 00:16 凌晨三点半的飞机 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 插入排序: public class InsertSort { public static int[] insertSort(int[] nums){ for(int i=1,j,current; i<nums.length;i++){ current= nums[i]; for(j=i-1;j>= 阅读全文
posted @ 2020-08-24 00:12 凌晨三点半的飞机 阅读(80) 评论(0) 推荐(0) 编辑
  2020年8月23日
摘要: 一、二分搜索(Binary Search): 二分搜索(折半搜索)的Wikipedia定义:是一种在有序数组中查找某一特定元素的搜索算法。从定义可知,运用二分搜索的前提是数组必须是排好序的。另外,输入并不一定是数组,也有可能是给定一个区间的起始和终止的位置。优点:搜索速度快,时间复杂度为O(logn 阅读全文
posted @ 2020-08-23 19:54 凌晨三点半的飞机 阅读(247) 评论(0) 推荐(0) 编辑