- 博客(23)
- 收藏
- 关注
原创 133. Clone Graph Leetcode Python
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each
2015-02-26 11:04:54 1774
原创 51. N-Queens Leetcode Python
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.
2015-02-20 06:53:54 2712
原创 Matrix Chain Multiplication-geeksforgeeks
(ABC)D = (AB)(CD) = A(BCD) calculate the least calculation.第一种方法穷举发,willl take np time.def matrixp(p,i,j): if i==j: return 0 k=i minval=10000000 while k<j: result=m
2015-02-18 22:15:18 429
原创 127. Word Ladder Leetcode Python
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate wo
2015-02-16 04:51:52 1872
原创 109.Convert Sorted List to Binary Search Tree Leetcode Python
Convert Sorted List to Binary Search Tree Total Accepted: 32343 Total Submissions: 117376 My Submissions Question Solution Given a singly linked list where elements are sorted in ascending order, co
2015-02-16 03:38:09 1099
原创 168. Excel Sheet Column Title Leetcode Python
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
2015-02-15 03:09:32 1099
原创 165. Compare Version Numbers Leetcode Python
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 You may assume that the version strings are non-empty and contain only digits and the . character
2015-02-15 02:38:34 1642
原创 171. Excel Sheet Column Number Leetcode Python
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3
2015-02-15 01:52:25 1343
原创 132. Palindrome Partitioning II Leetcode Python
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Retu
2015-02-15 00:30:32 700
原创 162. Find Peak Value Leetcode Python
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,
2015-02-14 23:35:30 471
原创 52. N-Queens II Leetcode Python
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.这题的解法是建一个board表示行比如n=4 时候board=[1,3,0,2] 表示 0Q00,000Q,Q000,00Q0
2015-02-11 04:28:41 1561
原创 amazon phone screen 1
1.shuffle deck of cards and draw cardsimport itertools,randomdeck=list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club']))random.shuffle(deck)for i in range(5): print deck[
2015-02-10 03:26:52 887
原创 82. Remove Duplicates from Sorted List II Leetcode Python
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given
2015-02-05 11:48:11 2439
原创 83. Remove Duplicates from Sorted List Leetcode Python
Given 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.定义一个pre 和cur1.当二者
2015-02-04 23:56:54 869
原创 67. Add Binary Leetcode Python
For example,a = "11"b = "1"Return "100".这题的做法和前面一题plus one 一样,区别在于需要将两个string先相加,再判断是否要进位。直接上代码吧。class Solution: # @param a, a string # @param b, a string # @return a string
2015-02-04 23:43:05 1167
原创 Tripadvisor 面经解答 -持续更新ing
2. Binary Search Tree Insertclass Node: def __init__(self,val): self.left=None self.right=None self.val=val def insertBST(root,node): if root==None:
2015-02-04 07:29:51 946
原创 63. Unique Path II Leetcode Python
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in th
2015-02-04 04:28:29 871
原创 58. Length of Last Word Leetcode Python
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
2015-02-04 01:01:09 799
原创 50. Pow(x,n) Leetcode Python
Implement pow(x, n).这题可以用recursive 和iterate 的解法。解的时候要注意负数。首先是 recursive的解:class Solution: # @param x, a float # @param n, a integer # @return a float def pow(self, x, n):
2015-02-04 00:19:52 2587
原创 59. Spiral Matrix II Leetcode Python
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9,
2015-02-03 23:48:58 1115
原创 54. Spiral Matrix Leetcode Python
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9
2015-02-03 23:32:40 690
原创 48. Rotate Image Leetcode Python
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?这题是要定义一个Layer 逐层 交换ABCDtemp=A
2015-02-03 12:54:03 857
原创 41. First Missing Positive Leetcode Python
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses cons
2015-02-03 04:40:20 1435
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人