LeetCode
文章平均质量分 60
zjxxyz123
这个作者很懒,什么都没留下…
展开
-
LeetCode 题解
数组问题LeetCode 283.Move ZeroesLeetCode 27.Remove ElementLeetCode 26. Remove Duplicates from Sorted ArrayLeetCode 80. Remove Duplicates from Sorted Array IILeetCode 75. Sort ColorsLeetCode 88. Me...原创 2018-05-12 11:53:34 · 690 阅读 · 0 评论 -
LeetCode 202. Happy Number
题目描述Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the sq...原创 2018-04-14 14:17:21 · 122 阅读 · 0 评论 -
LeetCode 290. Word Pattern
问题描述Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str....原创 2018-04-14 15:29:16 · 129 阅读 · 0 评论 -
LeetCode 205. Isomorphic Strings
问题描述Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with a...原创 2018-04-14 16:44:43 · 110 阅读 · 0 评论 -
LeetCode 451. Sort Characters By Frequency
题目描述Given a string, sort it in decreasing order based on the frequency of characters.Example: Input: “tree” Output: “eert” Explanation: ‘e’ appears twice while ‘r’ and ‘t’ both...原创 2018-04-14 19:24:20 · 169 阅读 · 0 评论 -
LeetCode 15. 3Sum
题目描述Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: he solution set must not...原创 2018-04-15 11:05:49 · 142 阅读 · 0 评论 -
LeetCode 18. 4Sum
问题描述Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum...原创 2018-04-15 15:33:31 · 130 阅读 · 0 评论 -
LeetCode 16. 3Sum Closest
问题描述Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input...原创 2018-04-15 21:05:42 · 125 阅读 · 0 评论 -
LeetCode 454. 4Sum II
题目描述Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit easier, all A, B, C, D have sam...原创 2018-04-15 21:38:06 · 145 阅读 · 0 评论 -
LeetCode 49. Group Anagrams
问题描述Given an array of strings, group anagrams together.Example: Input: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Output: [ [“ate”,”eat”,”tea”], [“nat”,”tan”], [“bat”] ...原创 2018-04-16 08:39:50 · 103 阅读 · 0 评论 -
LeetCode 447. Number of Boomerangs
问题描述Given n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of...原创 2018-04-16 09:41:27 · 143 阅读 · 0 评论 -
LeetCode 217. Contains Duplicate
问题描述Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every ele...原创 2018-04-16 14:05:45 · 130 阅读 · 0 评论 -
LeetCode 219. Contains Duplicate II
问题描述Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at m...原创 2018-04-16 14:18:14 · 163 阅读 · 0 评论 -
LeetCode 283.Move Zeroes
题目描述Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12], after calling ...原创 2018-04-10 21:38:40 · 163 阅读 · 0 评论 -
LeetCode 27.Remove Element
题目描述Given an array and a value, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array ...原创 2018-04-11 10:16:36 · 143 阅读 · 0 评论 -
LeetCode 220. Contains Duplicate III
问题描述Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute diff...原创 2018-04-16 16:45:02 · 159 阅读 · 0 评论 -
LeetCode 206. Reverse Linked List
问题描述Reverse a singly linked list.Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?地址代码实现见 剑指offer-反转链表原创 2018-04-16 17:38:00 · 142 阅读 · 0 评论 -
LeetCode 92. Reverse Linked List II
问题描述Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL....原创 2018-04-16 22:07:41 · 143 阅读 · 0 评论 -
LeetCode 26. Remove Duplicates from Sorted Array
题目描述Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modif...原创 2018-04-11 14:06:46 · 133 阅读 · 0 评论 -
LeetCode 86. Partition List
问题描述Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in ea...原创 2018-04-17 09:12:30 · 113 阅读 · 0 评论 -
LeetCode 328. Odd Even Linked List
问题描述Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do ...原创 2018-04-17 09:55:31 · 117 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers
问题描述You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and r...原创 2018-04-17 10:43:20 · 122 阅读 · 0 评论 -
LeetCode 80. Remove Duplicates from Sorted Array II
问题描述Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice? For example, Given sorted array nums = [1,1,1,2,2,3], Your function should return length = 5, with the first...原创 2018-04-11 15:53:20 · 127 阅读 · 0 评论 -
LeetCode 75. Sort Colors
问题描述Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the inte...原创 2018-04-11 17:23:28 · 136 阅读 · 0 评论 -
LeetCode 88. Merge Sorted Array
题目描述Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold a...原创 2018-04-11 18:24:00 · 127 阅读 · 0 评论 -
LeetCode 215. Kth Largest Element in an Array
题目描述Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example, Given [3,2,1,5,6,4] and k = 2, retur...原创 2018-04-11 21:56:55 · 167 阅读 · 0 评论 -
LeetCode 125. Valid Palindrome
问题描述Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, “A man, a plan, a canal: Panama” is a palindrome. “race a car” is n...原创 2018-04-12 09:39:37 · 111 阅读 · 0 评论 -
LeetCode 445. Add Two Numbers II
问题描述You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and r...原创 2018-04-17 18:25:16 · 121 阅读 · 0 评论 -
LeetCode 66. Plus One
问题描述Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each ...原创 2018-04-17 19:47:25 · 117 阅读 · 0 评论 -
LeetCode 203. Remove Linked List Elements
问题描述Remove all elements from a linked list of integers that have value val.Example: Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –>...原创 2018-04-17 20:37:36 · 108 阅读 · 0 评论 -
LeetCode 344. Reverse String
题目描述Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.地址代码实现双指针与 StringBufferclass Solution { public String ...原创 2018-04-12 10:05:05 · 126 阅读 · 0 评论 -
LeetCode 345. Reverse Vowels of a String
问题描述Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = “hello”, return “holle”. Example 2: Given s = “leetcode”, return “leotcede”. Not...原创 2018-04-12 10:37:40 · 120 阅读 · 0 评论 -
LeetCode 82. Remove Duplicates from Sorted List II
问题描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, retur...原创 2018-04-17 21:18:38 · 98 阅读 · 0 评论 -
LeetCode 83. Remove Duplicates from Sorted List
问题描述Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2-&...原创 2018-04-17 21:24:29 · 100 阅读 · 0 评论 -
LeetCode 21. Merge Two Sorted Lists
问题描述Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.地址问题分析dummy递归代码实现dummy public ...原创 2018-04-17 21:49:26 · 103 阅读 · 0 评论 -
LeetCode 11. Container With Most Water
题目描述Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find...原创 2018-04-12 14:18:51 · 108 阅读 · 0 评论 -
LeetCode 24. Swap Nodes in Pairs
问题描述Given a linked list, swap every two adjacent nodes and return its head.Example Given 1->2->3->4, you should return the list as 2->1->4->3.Note: Your algorithm shoul...原创 2018-04-18 08:22:33 · 118 阅读 · 0 评论 -
LeetCode 25. Reverse Nodes in k-Group
问题描述Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the num...原创 2018-04-18 10:11:16 · 132 阅读 · 0 评论 -
LeetCode 42. Trapping Rain Water
题目描述Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,...原创 2018-04-12 17:39:05 · 109 阅读 · 0 评论 -
LeetCode 147. Insertion Sort List
问题描述Sort a linked list using insertion sort.地址问题分析该题是在链表上实现插入排序。具体做法为,新建一个空链表,然后从原链表中每次取出一个节点,然后从前到后遍历新链表,找到待插入的位置,将该节点插入到新链表中。 注意,与反转部分链表的不同,这个是取出一个节点!!!代码实现 public ListNode i...原创 2018-04-18 15:34:52 · 110 阅读 · 0 评论