leetcode
InfoSecPractitioner
这个作者很懒,什么都没留下…
展开
-
[LeetCode]53. Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanat...转载 2018-09-12 23:08:24 · 200 阅读 · 0 评论 -
[LeetCode]118. Pascal's Triangle&119. Pascal's Triangle II
118. Pascal's Triangle119. Pascal's Triangle II转载 2016-10-01 15:53:39 · 253 阅读 · 0 评论 -
[LeetCode]2. Add Two Numbers&67. Add Binary
2. Add Two Numbers67. Add Binary转载 2016-10-16 13:48:32 · 461 阅读 · 0 评论 -
[LeetCode]70. Climbing Stairs
EasyYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?0ms:public int climbStairs(int n)转载 2016-09-29 17:28:49 · 205 阅读 · 0 评论 -
[LeetCode]206. Reverse Linked List&92. Reverse Linked List II
206. Reverse Linked List92. Reverse Linked List II转载 2016-09-29 17:08:54 · 246 阅读 · 0 评论 -
[LeetCode]83. Remove Duplicates from Sorted List
EasyGiven 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.2ms: public ListNode deleteD转载 2016-09-28 22:41:39 · 199 阅读 · 0 评论 -
[LeetCode]401. Binary Watch
EasyA binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a zero or one, with the least significant bit on转载 2016-09-28 21:58:36 · 243 阅读 · 0 评论 -
[LeetCode]169. Majority Element&229. Majority Element II
169. Majority Element229. Majority Element II转载 2016-09-28 19:57:21 · 226 阅读 · 0 评论 -
[LeetCode]387. First Unique Character in a String
EasyGiven a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.Examples:s = “leetcode” return 0.s = “loveleetcode”, return 2. Note: You may as转载 2016-09-28 16:40:30 · 210 阅读 · 0 评论 -
[LeetCode]404. Sum of Left Leaves
EasyFind the sum of all left leaves in a given binary tree.Example:3/ \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.9ms: pub转载 2016-09-28 15:21:25 · 233 阅读 · 0 评论 -
[LeetCode]15. 3Sum【&16. 3Sum Closest】
15. 3Sum16. 3Sum Closest转载 2016-10-11 21:08:15 · 431 阅读 · 0 评论 -
[LeetCode]1. Two Sum&167. Two Sum II - Input array is sorted
1 . Two Sum EasyGiven an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example: Given转载 2016-09-16 15:30:45 · 335 阅读 · 0 评论 -
[LeetCode]217. Contains Duplicate&219. Contains Duplicate II&220. Contains Duplicate III
217. Contains Duplicate219. Contains Duplicate II220. Contains Duplicate III转载 2016-09-28 23:30:19 · 306 阅读 · 0 评论 -
[LeetCode]257. Binary Tree Paths
EasyGiven a binary tree, return all root-to-leaf paths.For example, given the following binary tree:1 / \ 2 3 \ 5 All root-to-leaf paths are:[“1->2->5”, “1->3”]5ms:public List<String> bi转载 2016-10-01 16:24:53 · 246 阅读 · 0 评论 -
[LeetCode]112. Path Sum&113. Path Sum II
112 . Path Sum EasyGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below bin转载 2016-10-01 12:16:35 · 288 阅读 · 0 评论 -
[LeetCode]58. Length of Last Word
EasyGiven a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is define转载 2016-10-03 17:34:10 · 228 阅读 · 0 评论 -
[LeetCode]319. Bulb Switcher
MediumThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or turning转载 2016-09-17 10:48:31 · 356 阅读 · 0 评论 -
[Leetcode]160.Intersection of Two Linked Lists
160 Intersection of Two Linked Lists EasyWrite 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 ...转载 2018-07-02 21:09:54 · 218 阅读 · 0 评论 -
[LeetCode]242.Valid Anagram&383. Ransom Note&389. Find the Difference
242.Valid Anagram383. Ransom Note389. Find the Difference转载 2016-09-16 20:28:19 · 307 阅读 · 0 评论 -
[LeetCode]409. Longest Palindrome
EasyGiven a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example “Aa” is not cons转载 2016-10-07 00:25:07 · 373 阅读 · 0 评论 -
[LeetCode]39.Combination Sum&40.Combination Sum II&216.Combination Sum III&377.Combination Sum IV
39.Combination Sum40.Combination Sum II216.Combination Sum III377.Combination Sum IV转载 2016-10-06 23:44:30 · 455 阅读 · 0 评论 -
[LeetCode]223. Rectangle Area
Easy Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Rectangle Area Assume that转载 2016-10-05 23:53:38 · 260 阅读 · 0 评论 -
[LeetCode]7. Reverse Integer&190. Reverse Bits
7. Reverse Integer190. Reverse Bits转载 2016-10-05 17:04:24 · 238 阅读 · 0 评论 -
[LeetCode]400. Nth Digit
EasyFind 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 < 231).Example 1:Input: 3Ou转载 2016-10-05 21:26:59 · 259 阅读 · 0 评论 -
[LeetCode]38. Count and Say
EasyThe count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2,转载 2016-10-05 20:23:41 · 223 阅读 · 0 评论 -
[LeetCode]189. Rotate Array
EasyRotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note: Try to come up as many solutions as you can,转载 2016-10-05 15:55:24 · 246 阅读 · 0 评论 -
[LeetCode]198. House Robber&213. House Robber II&337. House Robber III
198. House Robber213. House Robber II337. House Robber III转载 2016-09-16 15:59:07 · 299 阅读 · 0 评论 -
[LeetCode]343. Integer Break
MediumGiven a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, re转载 2016-10-05 10:11:07 · 234 阅读 · 0 评论 -
[LeetCode]144. Binary Tree Preorder Traversal&94. Binary Tree Inorder Traversal
144. Binary Tree Preorder Traversal94. Binary Tree Inorder Traversal转载 2016-10-04 23:27:44 · 244 阅读 · 0 评论 -
[LeetCode]318. Maximum Product of Word Lengths
MediumGiven a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case转载 2016-10-04 16:58:01 · 294 阅读 · 0 评论 -
[LeetCode]238. Product of Array Except Self
MediumGiven an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n)转载 2016-10-04 16:27:34 · 209 阅读 · 0 评论 -
[LeetCode]204. Count Primes
EasyDescription:Count the number of prime numbers less than a non-negative number, n.超时: public int countPrimes(int n) { int[] primes = new int[n/2+1]; int p = 0; int i = 2;转载 2016-10-04 10:06:19 · 264 阅读 · 0 评论 -
[LeetCode]283. Move Zeroes&26. Remove Duplicates from Sorted Array
283. Move Zeroes26. Remove Duplicates from Sorted Array转载 2016-09-01 16:27:03 · 283 阅读 · 0 评论 -
[LeetCode]235. Lowest Common Ancestor of a Binary Search Tree&236. Lowest Common Ancestor of a Binar
235. Lowest Common Ancestor of a Binary Search Tree236. Lowest Common Ancestor of a Binar转载 2016-09-29 15:07:31 · 258 阅读 · 0 评论 -
[LeetCode]165. Compare Version Numbers
EasyCompare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and c转载 2016-09-16 21:20:03 · 213 阅读 · 0 评论 -
[LeetCode]168. Excel Sheet Column Title&171. Excel Sheet Column Number
168. Excel Sheet Column Title171. Excel Sheet Column Number转载 2016-09-17 10:24:01 · 207 阅读 · 0 评论 -
[LeetCode]226. Invert Binary Tree
EasyInvert a binary tree. 4/ \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 10ms: public TreeNode invertTree(TreeNode root) { if(root==null)转载 2016-09-17 10:15:51 · 166 阅读 · 0 评论 -
[LeetCode]100. Same Tree &129. Sum Root to Leaf Numbers
EasyGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.0ms: public boo转载 2016-09-17 10:13:59 · 184 阅读 · 0 评论 -
[LeetCode]21. Merge Two Sorted Lists
EasyMerge 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.2ms: public ListNode mergeTwoLists(ListNode l1, ListNode转载 2016-09-16 23:20:05 · 175 阅读 · 0 评论 -
[LeetCode]24. Swap Nodes in Pairs
EasyGiven 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. You ma转载 2016-09-16 23:18:57 · 167 阅读 · 0 评论