随笔分类 - Leetcode
Leetcode: Zigzag Iterator
摘要:Best Solution: O(N) This solution also works for K vectors Use a queue to store the iterators in different vectors. Every time we call next(), we pop
阅读全文
Leetcode: Wiggle Sort
摘要:Given an unsorted array nums, reorder it in-place such that nums[0] = nums[2] = nums[i - 1]如果i是偶数,nums[i] nums[i - 1], 则交换以后肯定有nums[i] =nums[i-1])) {...
阅读全文
Leetcode: Perfect Squares
摘要:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, ...
阅读全文
Leetcode: First Bad Version
摘要:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c...
阅读全文
Leetcode: Find the Celebrity
摘要:最佳做法:O(N)time, O(1)space The first pass is to pick out the candidate. If candidate knows i, then switch candidate. The second pass is to check whether
阅读全文
Leetcode: Integer to English Words
摘要:Career Cup 150 Pg 442 Think of Convert(19,323,984) = Process(19) + "million" + Process(323) + "thousand" + Process(984) + "" The Process is a process
阅读全文
Leetcode: Paint Fence
摘要:There is a fence with n posts, each post can be painted with one of the k colors.You have to paint all the posts such that no more than two adjacent f...
阅读全文
Leetcode: H-Index II
摘要:Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? Hint: Expected runtime complexity
阅读全文
Leetcode: H-Index
摘要:Hint: Sort first then scan: O(NlogN) time, O(1)space use another array: O(N) time, O(N) space(有点像counting sort) 我们额外使用一个大小为N+1的数组stats。stats[i]表示有多少文章
阅读全文
Leetcode: Closest Binary Search Tree Value II
摘要:Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target.Note:Given target value is a floating...
阅读全文
Leetcode: Encode and Decode Strings
摘要:If I choose / as spliter, how to ensure the other / wouldn't be seen as spliter? The idea is to store length of the str This one will be encoded as "6
阅读全文
Leetcode: Closest Binary Search Tree Value
摘要:Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.Note:Given target value is a floating...
阅读全文
Leetcode: Missing Number
摘要:Best Solution: Bit manipulation The basic idea is to use XOR operation. We all know that a^b^b =a, which means two xor operations with the same number
阅读全文
Leetcode: Graph Valid Tree && Summary: Detect cycle in undirected graph
摘要:This problem can be solved by using union find, reference this blog:https://segmentfault.com/a/1190000003791051 复杂度 时间 O(N^M) 空间 O(N) 思路 判断输入的边是否能构成一个
阅读全文
Leetcode: Paint House II
摘要:There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. Yo
阅读全文
Leetcode: Palindrome Permutation II
摘要:Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form...
阅读全文
Leetcode: Palindrome Permutation
摘要:Given a string, determine if a permutation of the string could form a palindrome.For example,"code" -> False, "aab" -> True, "carerac" -> True.Hint:Co...
阅读全文
Leetcode: Ugly Number
摘要:Write 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. For exa
阅读全文
Leetcode: Ugly Number II
摘要:Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6...
阅读全文
Leetcode: Single Number III
摘要:Lintcode 也有这道题 Single Number III example: 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 如例所示,最后两个数8,
阅读全文
浙公网安备 33010602011771号