- 博客(23)
- 收藏
- 关注
原创 539. Minimum Time Difference
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the list.Example 1:Input: ["23:59","00:00"]Output: 1N
2017-07-21 22:09:37 214
原创 Compare Version Numbers
Compare 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 co
2017-07-17 15:06:15 172
原创 560. Subarray Sum Equals K
这道题目使用的是hash+prefix sum的方法,这个也是我第一次知道还有prefix sum这个东西 所谓的prefix sum可以看看链接https://www.jiuzhang.com/qa/1178/代码中,pre_sum[s - k]就是为了得到是否存在一个prefix sum使得s - p = k ,从而得到一个满足连续子序列的和为k。class Solution(object):
2017-07-14 08:43:11 229
原创 300. Longest Increasing Subsequence
动态规划class Solution(object): def lengthOfLIS(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return 0 result = [num
2017-06-29 18:59:43 166
原创 303. Range Sum Query - Immutable
class NumArray(object): def __init__(self, nums): """ :type nums: List[int] """ self.sums = [0] s = 0 for v in nums: s += v
2017-06-29 16:14:41 157
原创 97. Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r
2017-06-29 14:56:09 170
原创 求解概率相关的题目的解法
Brief explanation for Reservoir Sampling111 WTIFS Reputation: 178PROBLEM:Choose k entries from n numbers. Make sure each number is selected with th
2017-06-28 20:01:16 295
原创 377. Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3] target = 4The possible co
2017-06-27 23:05:52 152
原创 319. Bulb Switcher
There 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 off i
2017-06-24 10:01:47 150
原创 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 same length o
2017-06-24 09:35:34 211
原创 343. Integer Break
Given 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, return 1
2017-06-22 22:39:33 166
原创 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false.Note: You may assume the s
2017-06-22 10:24:29 139
原创 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 given numb
2017-06-22 10:19:46 236
原创 609. Find Duplicate File in System
Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in terms of their p
2017-06-22 10:12:35 272
原创 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in this word
2017-06-22 09:48:28 134
原创 462. Minimum Moves to Equal Array Elements II
Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by 1
2017-06-22 09:43:33 179
原创 565. Array Nesting
A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].Sets S[K] for 0 <= K < N are defined as follows:S[K] = { A[K], A[A[K]], A[A[A
2017-06-22 09:35:30 205
原创 173. Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and hasN
2017-06-18 22:56:56 149
原创 162. Find Peak Element
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that case
2017-06-18 21:37:45 133
原创 230. Kth Smallest Element in a BST
My solution with a global variableclass Solution(object): def kthSmallest(self, root, k): """ :type root: TreeNode :type k: int :rtype: int """ self.
2017-06-17 21:14:18 124
原创 leetcode 404. Sum of Left Leaves
Find 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.python i
2017-06-17 20:53:16 123
原创 Leetcode 543. Diameter of Binary Tree
Leetcode 543. Diameter of Binary TreeGiven a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nod
2017-06-16 20:53:24 153
转载 java 通配符
Technorati 标记: 通配符,wildcard,java 本以为这会是一篇比较基础的博客,可一旦深究的时候,才发现很多有意思的东西,也发现了很多令人迷惑的地方。通配符是一个有趣的东西,如果你掌握了,会使你的代码更为通用(健壮性更强)。首先本文是在建立在java泛型基础之上的,如果你对泛型并不了解,可以点击 这里。同时为了对通配符的了解更为透切,定义如下几个类。publ
2015-09-26 19:43:23 142
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人