leetcode
YANG_BLOG
这个作者很懒,什么都没留下…
展开
-
LeetCode #19 Remove Nth Node From End of List
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: # @param {ListNode} head # @param {intege原创 2015-07-23 11:57:42 · 247 阅读 · 0 评论 -
LeetCode #20 Valid Parentheses
class Solution: # @param {string} s # @return {boolean} def isValid(self, s): tack = [] for i in range(0,len(s)): if s[i] == '(' or s[i] == '{' or s[i] == '[' o原创 2015-07-24 08:37:15 · 308 阅读 · 0 评论 -
归并排序 MergeSort
def mergeSort(arry,left,right): if left < right: mid = (left + right) / 2 mergeSort(arry,left,mid) mergeSort(arry,mid+1,right) mergeArry(arry,left,right,mid) return arrydef mergeArry(arry转载 2015-08-16 11:14:23 · 296 阅读 · 0 评论 -
LeetCode #21 Merge Two Sorted Lists
# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: # @param {ListNode} l1 # @param {ListNode原创 2015-08-04 21:37:18 · 256 阅读 · 0 评论 -
LeetCode #22 Generate Parentheses
class Solution: # @param {integer} n # @return {string[]} def generateParenthesis(self, n): left = right = n s = '' sset = set() self.parentGen(s,left,righ转载 2015-08-05 12:01:29 · 275 阅读 · 0 评论 -
LeetCode #1 Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2015-07-03 07:50:18 · 409 阅读 · 0 评论 -
LeetCode #27 Remove Element
class Solution: # @param {integer[]} nums # @param {integer} val # @return {integer} def removeElement(self, nums, val): size = 0 for i in range(0,len(nums)):原创 2015-08-05 17:07:19 · 243 阅读 · 0 评论 -
LeetCode #26 Remove Duplicates from Sorted Array
class Solution: # @param {integer[]} nums # @return {integer} def removeDuplicates(self, nums): if len(nums) == 0: return 0 if len(nums) == 1: retur原创 2015-08-05 16:31:08 · 265 阅读 · 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原创 2015-07-03 07:51:55 · 381 阅读 · 0 评论 -
LeetCode #18 4Sum
class Solution: # @param {integer[]} nums # @param {integer} target # @return {integer[][]} def fourSum(self, nums, target): valMap = {} ans = set() nums.sort()转载 2015-07-23 10:49:38 · 275 阅读 · 0 评论 -
LeetCode #17 Letter Combinations of a Phone Number
class Solution: # @param {string} digits # @return {string[]} def letterCombinations(self, digits): depth = 0 ans = [] path = "" self.comb(depth,ans,digits,转载 2015-07-21 11:25:43 · 354 阅读 · 0 评论 -
快速排序 QuickSort
def adjustArry(arry,left,right): i = left j = right x = arry[i] while i < j: while i= x: j-=1 if arry[j] < x: arry[i] = arry[j] i+=1 while i<j and arry[i] <= x: i+=1 if arry[转载 2015-08-11 17:02:31 · 282 阅读 · 0 评论 -
LeetCode#4 Median of Two Sorted Arrays (2)
def findKth(self,a,b,k,aStart,aEnd,bStart,bEnd): aLen = aEnd - aStart + 1 bLen = bEnd - bStart + 1 if aLen == 0: return b[bStart+k] if bLe转载 2015-07-09 12:23:29 · 388 阅读 · 0 评论 -
LeetCode #7 Reverse Integer
class Solution: # @param {integer} x # @return {integer} def reverse(self, x): isNegative = 1 y = 0.0 if x < 0: isNegative = -1 x = abs(x)原创 2015-07-11 19:00:47 · 456 阅读 · 0 评论 -
LeetCode #14 Longest Common Prefix
class Solution: # @param {string[]} strs # @return {string} def longestCommonPrefix(self, strs): if len(strs) == 0: return "" #find the longest substr原创 2015-07-12 10:40:16 · 293 阅读 · 0 评论 -
LeetCode #3 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-07-03 13:43:14 · 307 阅读 · 0 评论 -
LeetCode#4 Median of Two Sorted Arrays
There 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)).class Solution: #原创 2015-07-04 07:21:25 · 372 阅读 · 0 评论 -
LeetCode#5 Longest Palindromic Substring
class Solution: # @param {string} s # @return {string} def longestPalindrome(self, s): lenS = len(s) maxLen = 0 maxStr = "" for i in range(0,lenS):原创 2015-07-11 18:17:50 · 454 阅读 · 0 评论 -
LeetCode #15 3Sum
class Solution: # @param {integer[]} nums # @return {integer[][]} def threeSum(self, nums): if nums == None: return None if len(nums) == 0: return [原创 2015-07-12 15:44:12 · 269 阅读 · 0 评论 -
LeetCode #9 Palindrome Number
class Solution: # @param {integer} x # @return {boolean} def isPalindrome(self, x): if x < 0: return False y = 0 cX = x while x:原创 2015-07-12 10:02:45 · 303 阅读 · 0 评论 -
LeetCode #16 3Sum Closest
class Solution: # @param {integer[]} nums # @param {integer} target # @return {integer} def threeSumClosest(self, nums, target): if len(nums) == 0: return None原创 2015-07-17 17:19:54 · 279 阅读 · 0 评论 -
LeetCode #58 Length of Last Word
Given 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 defined a原创 2015-10-08 17:48:34 · 311 阅读 · 0 评论