
LeetCode与算法
不积跬步无以至千里,
不积小流无以成江海。
燕雀于鸿鹄
不积跬步无以至千里
不积小流无以成江海
展开
-
剑指LeetCode -- 第二题 -- 两数相加 -- 中等
同样属于比较简单的题,注意一下进位就行了。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { pub...原创 2019-07-27 16:37:18 · 161 阅读 · 0 评论 -
剑指LeetCode -- 第一题 -- 两数之和 -- 简单
这道题比较简单,用了Map对key值查找的常数时间的特性, 使得该算法的时间复杂度为O(n)。class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> numCache = new HashMap<Integer,...原创 2019-07-27 16:33:41 · 121 阅读 · 0 评论 -
剑指LeetCode -- 第四十题 -- 组合总和 II -- 中等
class Solution { private List<List<Integer>> results = new ArrayList<>(); public List<List<Integer>> combinationSum2(int[] candidates, int target) ...原创 2019-10-01 16:24:50 · 140 阅读 · 0 评论 -
剑指LeetCode -- 第三十九题 -- 组合总和 -- 中等
class Solution { List<List<Integer>> results = new ArrayList<>(); public List<List<Integer>> combinationSum(int[] candidates, int target) { ...原创 2019-10-01 15:51:33 · 134 阅读 · 0 评论 -
剑指LeetCode -- 第十七题 -- 电话号码的字母组合 -- 中等
class Solution { private List<String> results = new ArrayList<String>(); private Map<String, String> phones = new HashMap<String, String>() { { ...原创 2019-10-01 10:22:13 · 160 阅读 · 0 评论 -
剑指LeetCode -- 第三十五题 -- 搜索插入位置 -- 简单
class Solution { public int searchInsert(int[] nums, int target) { int result = -1, L = 0, R = nums.length - 1; while(L <= R) { int mid = (L + R) / 2; ...原创 2019-10-01 00:22:59 · 133 阅读 · 0 评论 -
剑指LeetCode -- 第三十四题 -- 在排序数组中查找元素的第一个和最后一个位置 -- 中等
class Solution { public int[] searchRange(int[] nums, int target) { // int[] result = {-1, -1}; int L = 0, R = nums.length - 1, cursor = -1; while(L <= R) { ...原创 2019-10-01 00:11:34 · 123 阅读 · 0 评论 -
剑指LeetCode -- 第二十六题 -- 删除排序数组中的重复项 -- 简单
class Solution { public int removeDuplicates(int[] nums) { if(nums.length < 2) return nums.length; int j = 0; for(int i = 0; i < nums.length; i++) { ...原创 2019-09-30 16:15:38 · 112 阅读 · 0 评论 -
剑指LeetCode -- 第十八题 -- 四数之和 -- 中等
class Solution { public List<List<Integer>> fourSum(int[] nums, int target) { List<List<Integer>> result = new ArrayList<List<Integer>>(); Arra...原创 2019-09-30 15:40:00 · 155 阅读 · 0 评论 -
剑指LeetCode -- 第十六题 -- 最接近的三数之和 -- 中等
class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); if(nums.length < 3) return target; int result = nums[0] + nums[1] + nums[2]; ...原创 2019-09-30 14:57:28 · 146 阅读 · 0 评论 -
剑指LeetCode -- 第十五题 -- 三数之和 -- 中等
class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> results = new ArrayList<List<Integer>>(); Arrays.sort(nu...原创 2019-09-30 12:23:16 · 109 阅读 · 0 评论 -
剑指LeetCode -- 第五题 -- 最长回文子串 -- 中等
class Solution { public String longestPalindrome(String s) { if(s == null || s.length() <= 1) { return s; } int start = 0, end = 0; for...原创 2019-09-27 15:33:02 · 118 阅读 · 0 评论 -
剑指LeetCode -- 第四题 -- 寻找两个有序数组的中位数 -- 困难
class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int n1Len = nums1.length; int n2Len = nums2.length; int i = 0, j = 0; List<Int...原创 2019-09-26 23:03:14 · 273 阅读 · 1 评论 -
剑指LeetCode -- 第三题 -- 无重复字符串最长子串 -- 中等
解法一class Solution { public int lengthOfLongestSubstring(String s) { String temp = ""; int maxLen = s.length() > 0 ? 1 : 0; int index = 0; char c; for(...原创 2019-09-26 22:13:58 · 145 阅读 · 0 评论 -
剑指LeetCode -- 第七百零七题 -- 设计链表 -- 简单
class MyLinkedList { private final ListNode list; private ListNode head; private ListNode rear; private int length; /** Initialize your data structure here. */ publ...原创 2019-10-03 14:13:24 · 467 阅读 · 2 评论