leetcode
Goofiness
这个作者很懒,什么都没留下…
展开
-
[LeetCode]Maximum Subarray Sum with One Deletion@Golang
Maximum Subarray Sum with One DeletionGiven an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to ...原创 2019-11-12 22:48:28 · 398 阅读 · 0 评论 -
[LeetCode]Number of Dice Rolls With Target Sum@Golang
Number of Dice Rolls With Target SumYou have d dice, and each die has f faces numbered 1, 2, …, f.Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the su...原创 2019-11-12 22:12:21 · 282 阅读 · 0 评论 -
[LeetCode]Longest Common Subsequence@Golang
Longest Common SubsequenceGiven two strings text1 and text2, return the length of their longest common subsequence.A subsequence of a string is a new string generated from the original string with s...原创 2019-11-08 09:06:36 · 274 阅读 · 0 评论 -
[LeetCode]Stone Game II@Golang
Stone Game IIAlex and Lee continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of ...原创 2019-11-06 22:24:05 · 178 阅读 · 0 评论 -
[LeetCode]Largest 1-Bordered Square@Golang
Largest 1-Bordered SquareGiven a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn’t exist in the grid.Exa...原创 2019-11-06 16:14:20 · 113 阅读 · 0 评论 -
[LeetCode]Minimum Cost Tree From Leaf Values@Golang
Minimum Cost Tree From Leaf ValuesGiven an array arr of positive integers, consider all binary trees such that:Each node has either 0 or 2 children;The values of arr correspond to the values of eac...原创 2019-11-05 16:35:58 · 165 阅读 · 0 评论 -
[LeetCode]Filling Bookcase Shelves@Golang
Filling Bookcase ShelvesWe have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1].We want to place these books in order onto bookcase shelves that have total width ...原创 2019-11-02 00:06:40 · 163 阅读 · 0 评论 -
[LeetCode]Last Stone Weight II@Golang
Last Stone Weight IIWe have a collection of rocks, each rock has a positive integer weight.Each turn, we choose any two rocks and smash them together. Suppose the stones have weights x and y with x...原创 2019-10-31 23:34:16 · 204 阅读 · 0 评论 -
[LeetCode]Longest String Chain@Golang
Longest String ChainGiven a list of words, each word consists of English lowercase letters.Let’s say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to...原创 2019-10-30 23:56:05 · 126 阅读 · 0 评论 -
[LeetCode]Longest Arithmetic Sequence@Golang
Longest Arithmetic SequenceGiven an array A of integers, return the length of the longest arithmetic subsequence in A.Recall that a subsequence of A is a list A[i_1], A[i_2], …, A[i_k] with 0 <= ...原创 2019-10-29 23:29:21 · 102 阅读 · 0 评论 -
[LeetCode]Video Stitching@Golang
Video StitchingYou are given a series of video clips from a sporting event that lasted T seconds. These video clips can be overlapping with each other and have varied lengths.Each video clip clips[...原创 2019-10-21 18:40:59 · 140 阅读 · 0 评论 -
[LeetCode]Minimum Cost For Tickets@Golang
Minimum Cost For TicketsIn a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you will travel is given as an array days. Each ...原创 2019-10-21 11:26:03 · 133 阅读 · 0 评论 -
[LeetCode]Longest Turbulent Subarray@Golang
Longest Turbulent SubarrayA subarray A[i], A[i+1], …, A[j] of A is said to be turbulent if and only if:For i <= k < j, A[k] > A[k+1] when k is odd, and A[k] < A[k+1] when k is even;OR, ...原创 2019-10-17 15:33:33 · 122 阅读 · 0 评论 -
[LeetCode]Numbers With Same Consecutive Differences@Golang
Numbers With Same Consecutive DifferencesReturn all non-negative integers of length N such that the absolute difference between every two consecutive digits is K.Note that every number in the answer...原创 2019-10-16 22:37:54 · 161 阅读 · 0 评论 -
[LeetCode]Minimum Falling Path Sum@Golang
Minimum Falling Path SumGiven a square array of integers A, we want the minimum sum of a falling path through A.A falling path starts at any element in the first row, and chooses one element from ea...原创 2019-10-15 11:21:41 · 83 阅读 · 0 评论 -
[LeetCode]Bitwise ORs of Subarrays@Golang
Bitwise ORs of SubarraysWe have an array A of non-negative integers.For every (contiguous) subarray B = [A[i], A[i+1], …, A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obt...原创 2019-10-14 11:27:47 · 101 阅读 · 0 评论 -
Two sum
Two sum:Given 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, and you may not use t...原创 2018-09-25 20:11:45 · 143 阅读 · 0 评论 -
Two sum II - Input array is sorted
Two sum II:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of th...原创 2018-09-26 16:10:33 · 91 阅读 · 0 评论 -
Number of 1 Bits
Number of i BitsWrite a function that takes an unsigned integer and returns the number of ‘1’ bits it has (also known as the Hamming weight).ExampleInput: 11Output: 3Explanation: Integer 11 ha...原创 2018-10-11 19:46:11 · 106 阅读 · 1 评论 -
Two sum IV - Input is a BST
Two sum IV:Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example:Input: 5 / \ 3 6...原创 2018-09-27 20:38:11 · 170 阅读 · 0 评论 -
Power of Two
Power of TwoGiven an integer, write a function to determine if it is a power of two.ExampleInput: 1Output: trueExplanation: 20 = 1Input: 16Output: trueExplanation: 24 = 16Input: 218Output...原创 2018-10-12 19:19:25 · 80 阅读 · 0 评论 -
Prime Number of Set Bits in Binary Representation
Prime Number of Set Bits in Binary RepresentationGiven two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representatio...原创 2018-10-18 22:39:05 · 157 阅读 · 0 评论 -
Reverse Integer
Reverse IntegerGiven a 32-bit signed integer, reverse digits of an integer.ExampleInput: 123Output: 321Input: -123Output: -321Input: 120Output: 21NoteAssume we are dealing with an envir...原创 2018-10-09 20:14:56 · 118 阅读 · 0 评论 -
Power of Three
Power of ThreeGiven an integer, write a function to determine if it is a power of three.ExampleInput: 27Output: trueInput: 45Output: falseSolutionclass Solution(object): def isPowerOfT...原创 2018-10-16 18:59:43 · 190 阅读 · 0 评论 -
Power of Four
Power of FourGiven an integer (signed 32 bits), write a function to check whether it is a power of 4.ExampleInput: 16Output: trueInput: 5Output: falseSolutionclass Solution(object): de...原创 2018-10-16 19:15:39 · 88 阅读 · 0 评论 -
Reverse Bits
Reverse BitsReverse bits of a given 32 bits unsigned integer.ExampleInput: 43261596Output: 964176192Explanation: 43261596 represented in binary as 00000010100101000001111010011100,return 9641...原创 2018-10-10 20:10:52 · 155 阅读 · 2 评论 -
Binary Number with Alternating Bits
Binary Number with Alternating BitsGiven a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.ExampleInput: 5Output: TrueEx...原创 2018-10-17 20:54:12 · 121 阅读 · 0 评论 -
Single Number II
Single Number IIGiven a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one.Note:Your algorithm should have a linear run...原创 2018-10-22 21:12:30 · 137 阅读 · 0 评论 -
Find the Duplicate Number
Find the Duplicate NumberGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is on...原创 2018-10-25 21:37:57 · 222 阅读 · 0 评论 -
Single Number III
Single Number IIIGiven an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.Example...原创 2018-10-23 21:52:49 · 84 阅读 · 0 评论 -
Single Number
Single NumberGiven a non-empty 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 ...原创 2018-10-23 21:57:12 · 128 阅读 · 0 评论 -
Add Two Numbers
Add Two NumbersYou 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 num...原创 2018-10-29 23:40:52 · 75 阅读 · 0 评论 -
Missing Number
Missing NumberGiven an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.ExampleInput: [3,0,1]Output: 2NoteYour algorithm should run ...原创 2018-10-24 21:05:57 · 93 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.ExampleInput: “abcabcbb”Output: 3Explanation: The answer is ...原创 2018-10-30 23:34:23 · 76 阅读 · 0 评论 -
Linked List Cycle II
Linked List Cycle IIGiven 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 ext...原创 2018-11-01 21:35:14 · 79 阅读 · 0 评论 -
Palindrome Number
Palindrome NumberDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.ExampleInput: 121Output: trueInput: -121Output: falseExpl...原创 2018-11-03 22:24:20 · 72 阅读 · 0 评论 -
Linked List Cycle
Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Solution# Definition for singly-linked list.# class ListNode(object...原创 2018-11-06 21:35:28 · 97 阅读 · 0 评论 -
Ugly Number
Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.ExampleInput: 6Output: trueExplanation:...原创 2018-11-09 20:31:01 · 126 阅读 · 0 评论 -
Median of Two Sorted Arrays
Median of Two Sorted ArraysThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n))....原创 2018-11-02 11:29:24 · 77 阅读 · 0 评论 -
Integer to Roman
Integer to RomanFor example, two is written as II in Roman numeral, just two one’s added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, whi...原创 2018-11-07 10:07:58 · 107 阅读 · 0 评论