![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 58
David_DLUT
这个作者很懒,什么都没留下…
展开
-
LeetCode 445. Add Two Numbers II
You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-12-30 13:24:59 · 246 阅读 · 0 评论 -
LeetCode 413. Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequenc原创 2016-12-30 13:17:54 · 224 阅读 · 0 评论 -
LeetCode 400. Nth Digit
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...Note:n is positive and will fit within the range of a 32-bit signed integer (n 31).Example 1:Input原创 2016-12-30 13:16:39 · 335 阅读 · 0 评论 -
LeetCode 397. Integer Replacement
Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum number o原创 2016-12-30 13:15:04 · 309 阅读 · 0 评论 -
LeetCode 396. Rotate Function
Given an array of integers A and let n to be its length.Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a "rotation function" F on A as follow:原创 2016-12-30 13:14:17 · 238 阅读 · 0 评论 -
LeetCode 372. Super Pow
Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example1:a = 2b = [3]Result: 8Example原创 2016-12-30 13:13:19 · 269 阅读 · 0 评论 -
LeetCode 368. Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple solution原创 2016-12-30 13:12:45 · 207 阅读 · 0 评论 -
LeetCode 367. Valid Perfect Square
Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16Return原创 2016-12-30 13:11:37 · 215 阅读 · 0 评论 -
LeetCode 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne原创 2016-12-30 12:49:51 · 215 阅读 · 0 评论 -
LeetCode 415. Add Strings
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits 0-9.B原创 2016-12-30 13:18:52 · 257 阅读 · 0 评论 -
LeetCode 423. Reconstruct Original Digits from English
Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.Note:Input contains only lowercase English letters.Input is g原创 2016-12-30 13:19:52 · 269 阅读 · 0 评论 -
LeetCode 441. Arranging Coins
You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be formed.原创 2016-12-30 13:23:35 · 205 阅读 · 0 评论 -
LeetCode 143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t原创 2016-12-30 12:40:32 · 358 阅读 · 0 评论 -
LeetCode 477. Total Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Now your job is to find the total Hamming distance between all pairs of the giv原创 2017-01-01 16:49:17 · 455 阅读 · 0 评论 -
547. Friend Circles
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is adirect friend of B, and B is a direct friend of C, then原创 2017-05-06 22:00:17 · 394 阅读 · 0 评论 -
542. 01 Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 00 1 00 0 0Output:0 0 00 1 00原创 2017-03-28 21:54:23 · 318 阅读 · 0 评论 -
LeetCode 92. Reverse Linked List II
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* re原创 2016-12-30 10:53:22 · 208 阅读 · 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 each of原创 2016-12-30 10:54:28 · 259 阅读 · 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->3.Subscribe to see wh原创 2016-12-30 11:14:46 · 193 阅读 · 0 评论 -
LeetCode 453. Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Ou原创 2016-12-30 13:25:33 · 221 阅读 · 0 评论 -
LeetCode 234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?/** * Definition for singly-linked list. * struct ListNode { * int va原创 2016-12-30 12:55:19 · 200 阅读 · 0 评论 -
LeetCode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2016-12-30 13:01:24 · 214 阅读 · 0 评论 -
LeetCode 137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2016-12-30 12:39:14 · 215 阅读 · 0 评论 -
LeetCode 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?/*原创 2016-12-30 12:38:21 · 194 阅读 · 0 评论 -
LeetCode 136. Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e原创 2016-12-30 12:32:38 · 198 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?/** * Definition for singly-linked list. * struct ListNode { * int val; *原创 2016-12-30 11:21:19 · 204 阅读 · 0 评论 -
LeetCode 109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Subscribe to see which companies asked this question/** * Definition for singly-原创 2016-12-30 11:20:15 · 205 阅读 · 0 评论 -
LeetCode 61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL./** * Definition for singly-link原创 2016-12-30 11:17:53 · 198 阅读 · 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, return 1->2->5.Given 1->1-原创 2016-12-30 11:16:02 · 211 阅读 · 0 评论 -
LeetCode 453. Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Ou原创 2016-12-29 23:06:04 · 233 阅读 · 0 评论 -
LeetCode 147. Insertion Sort List
Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */原创 2016-12-30 12:42:17 · 191 阅读 · 0 评论 -
LeetCode 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) :原创 2016-12-30 12:43:08 · 159 阅读 · 0 评论 -
LeetCode 160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2016-12-30 12:44:23 · 176 阅读 · 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 it in原创 2016-12-30 13:06:04 · 238 阅读 · 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.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2016-12-30 13:04:14 · 202 阅读 · 0 评论 -
LeetCode 24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2016-12-30 13:02:57 · 177 阅读 · 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./** * Definition for singly-linked list. * struct Lis原创 2016-12-30 12:48:56 · 179 阅读 · 0 评论 -
LeetCode 206. Reverse Linked List
Reverse a singly linked list./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solu原创 2016-12-30 12:48:22 · 230 阅读 · 0 评论 -
LeetCode 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** * Definition for si原创 2016-12-30 12:46:49 · 194 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-12-30 12:45:47 · 203 阅读 · 0 评论