Skip to content

Commit

Permalink
update at 2018-05-28
Browse files Browse the repository at this point in the history
  • Loading branch information
bonfy committed May 28, 2018
1 parent 1060ebf commit 23a3f14
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 72 deletions.
6 changes: 0 additions & 6 deletions 071-simplify-path/simplify-path.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@
# path = "/home/", => "/home"
# path = "/a/./b/../../c/", => "/c"
#
# click to show corner cases.
#
# Corner Cases:
#
#  
#
#  
#
#
# Did you consider the case where path = "/../"?
# In this case, you should return "/".
Expand Down
26 changes: 19 additions & 7 deletions 227-basic-calculator-ii/basic-calculator-ii.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,33 @@
#
# The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.
#
# You may assume that the given expression is always valid.
# Example 1:
#
# Some examples:
#
# "3+2*2" = 7
# " 3/2 " = 1
# " 3+5 / 2 " = 5
# Input: "3+2*2"
# Output: 7
#
#
# Example 2:
#
#
# Note: Do not use the eval built-in library function.
# Input: " 3/2 "
# Output: 1
#
# Example 3:
#
#
# Input: " 3+5 / 2 "
# Output: 5
#
#
# Note:
#
#
# You may assume that the given expression is always valid.
# Do not use the eval built-in library function.
#
#
# Credits:Special thanks to @ts for adding this problem and creating all test cases.


class Solution(object):
Expand Down
25 changes: 16 additions & 9 deletions 240-search-a-2d-matrix-ii/search-a-2d-matrix-ii.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
# Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
#
#
# Integers in each row are sorted in ascending from left to right.
# Integers in each column are sorted in ascending from top to bottom.
#
# Integers in each row are sorted in ascending from left to right.
# Integers in each column are sorted in ascending from top to bottom.
#
#
#
#
# For example,
#
# Consider the following matrix:
#
Expand All @@ -25,8 +20,20 @@
# ]
#
#
# Given target = 5, return true.
# Given target = 20, return false.
# Example 1:
#
#
# Input: matrix, target = 5
# Output: true
#
#
# Example 2:
#
#
# Input: matrix, target = 20
# Output: false
#
#


class Solution(object):
Expand Down
18 changes: 14 additions & 4 deletions 242-valid-anagram/valid-anagram.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# -*- coding:utf-8 -*-


# Given two strings s and t, write a function to determine if t is an anagram of s.
# Given two strings s and t , write a function to determine if t is an anagram of s.
#
# Example 1:
#
#
# Input: s = "anagram", t = "nagaram"
# Output: true
#
#
# Example 2:
#
#
# Input: s = "rat", t = "car"
# Output: false
#
# For example,
# s = "anagram", t = "nagaram", return true.
# s = "rat", t = "car", return false.
#
# Note:
# You may assume the string contains only lowercase alphabets.
Expand Down
31 changes: 25 additions & 6 deletions 263-ugly-number/ugly-number.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,37 @@

# 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 example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
# Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.
#
# Note:
# Example 1:
#
#
# 1 is typically treated as an ugly number.
# Input is within the 32-bit signed integer range.
# Input: 6
# Output: true
# Explanation: 6 = 2 × 3
#
# Example 2:
#
#
# Input: 8
# Output: true
# Explanation: 8 = 2 × 2 × 2
#
#
# Example 3:
#
#
# Input: 14
# Output: false
# Explanation: 14 is not ugly since it includes another prime factor 7.
#
#
# Note:
#
#
# 1 is typically treated as an ugly number.
# Input is within the 32-bit signed integer range: [−231,  231 − 1].
#
# Credits:
# Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
#


Expand Down
13 changes: 9 additions & 4 deletions 264-ugly-number-ii/ugly-number-ii.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# -*- coding:utf-8 -*-


#
# Write a program to find the n-th ugly number.
#
# Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. 
#
# Example:
#
#
# Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.
# Input: n = 10
# Output: 12
# Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.
#
# Note:  
#
#
# Note that 1 is typically treated as an ugly number, and n does not exceed 1690.
# 1 is typically treated as an ugly number.
# n does not exceed 1690.
#
#
# Credits:Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.


class Solution(object):
Expand Down
17 changes: 8 additions & 9 deletions 274-h-index/h-index.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# -*- coding:utf-8 -*-


#
# Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.
#
#
#
# According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each."
#
# Example:
#
#
# For example, given citations = [3, 0, 6, 1, 5], which means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively. Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, his h-index is 3.
#
#
#
# Note: If there are several possible values for h, the maximum one is taken as the h-index.
# Input: citations = [3,0,6,1,5]
# Output: 3
# Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had
# received 3, 0, 6, 1, 5 citations respectively.
#   Since the researcher has 3 papers with at least 3 citations each and the remaining
#   two with no more than 3 citations each, his h-index is 3.
#
# Note: If there are several possible values for h, the maximum one is taken as the h-index.
#
# Credits:Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.


class Solution(object):
Expand Down
15 changes: 14 additions & 1 deletion 275-h-index-ii/h-index-ii.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# -*- coding:utf-8 -*-


# Given an array of citations in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.
#
# Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
# According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than hcitations each."
#
# Example:
#
#
# Input: citations = [0,1,3,5,6]
# Output: 3
# Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had
# received 0, 1, 3, 5, 6 citations respectively.
#   Since the researcher has 3 papers with at least 3 citations each and the remaining
#   two with no more than 3 citations each, his h-index is 3.
#
# Note: If there are several possible values for h, the maximum one is taken as the h-index.
#


Expand Down
23 changes: 12 additions & 11 deletions 313-super-ugly-number/super-ugly-number.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# -*- coding:utf-8 -*-


# Write a program to find the nth super ugly number.
#
# Write a program to find the nth super ugly number.
# Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k.
#
# Example:
#
#
# Super ugly numbers are positive numbers whose all prime factors are in the given prime list
# primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32]
# is the sequence of the first 12 super ugly numbers given primes
# = [2, 7, 13, 19] of size 4.
# Input: n = 12, primes = [2,7,13,19]
# Output: 32
# Explanation: [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12
# super ugly numbers given primes = [2,7,13,19] of size 4.
#
# Note:
#
#
# Note:
# (1) 1 is a super ugly number for any given primes.
# (2) The given numbers in primes are in ascending order.
# (3) 0 < k ≤ 100, 0 < n ≤ 106, 0 < primes[i] < 1000.
# (4) The nth super ugly number is guaranteed to fit in a 32-bit signed integer.
# 1 is a super ugly number for any given primes.
# The given numbers in primes are in ascending order.
# 0 < k ≤ 100, 0 < n ≤ 106, 0 < primes[i] < 1000.
# The nth super ugly number is guaranteed to fit in a 32-bit signed integer.
#
#
# Credits:Special thanks to @dietpepsi for adding this problem and creating all test cases.


class Solution(object):
Expand Down
24 changes: 11 additions & 13 deletions 324-wiggle-sort-ii/wiggle-sort-ii.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# -*- coding:utf-8 -*-


# Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....
#
# Given an unsorted array nums, reorder it such that
# nums[0] < nums[1] > nums[2] < nums[3]....
# Example 1:
#
#
# Input: nums = [1, 5, 1, 1, 6, 4]
# Output: One possible answer is [1, 4, 1, 5, 1, 6].
#
# Example:
# (1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6].
# (2) Given nums = [1, 3, 2, 2, 3, 1], one possible answer is [2, 3, 1, 3, 1, 2].
# Example 2:
#
#
# Input: nums = [1, 3, 2, 2, 3, 1]
# Output: One possible answer is [2, 3, 1, 3, 1, 2].
#
# Note:
# You may assume all input has valid answer.
# Note:
# You may assume all input has valid answer.
#
# Follow Up:
# Can you do it in O(n) time and/or in-place with O(1) extra space?
#
#
# Follow Up:
# Can you do it in O(n) time and/or in-place with O(1) extra space?
#
#
# Credits:Special thanks to @dietpepsi for adding this problem and creating all test cases.


class Solution(object):
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# :pencil2: Leetcode Solutions with Python,Javascript
Update time: 2018-05-02 09:36:42
Update time: 2018-05-28 15:37:15

Auto created by [leetcode_generate](https://github.com/bonfy/leetcode)

I have solved **97 / 742** problems
I have solved **97 / 758** problems
while there are **133** problems still locked.

If you want to use this tool please follow this [Usage Guide](https://github.com/bonfy/leetcode/blob/master/README_leetcode_generate.md)
Expand Down Expand Up @@ -758,3 +758,19 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
|852|[friends-of-appropriate-ages](https://leetcode.com/problems/friends-of-appropriate-ages)||[:memo:](https://leetcode.com/articles/friends-of-appropriate-ages/)|Medium|
|853|[most-profit-assigning-work](https://leetcode.com/problems/most-profit-assigning-work)||[:memo:](https://leetcode.com/articles/most-profit-assigning-work/)|Medium|
|854|[making-a-large-island](https://leetcode.com/problems/making-a-large-island)||[:memo:](https://leetcode.com/articles/making-a-large-island/)|Hard|
|855|[unique-letter-string](https://leetcode.com/problems/unique-letter-string)||[:memo:](https://leetcode.com/articles/unique-letter-string/)|Hard|
|856|[consecutive-numbers-sum](https://leetcode.com/problems/consecutive-numbers-sum)||[:memo:](https://leetcode.com/articles/consecutive-numbers-sum/)|Medium|
|857|[positions-of-large-groups](https://leetcode.com/problems/positions-of-large-groups)||[:memo:](https://leetcode.com/articles/positions-of-large-groups/)|Easy|
|858|[masking-personal-information](https://leetcode.com/problems/masking-personal-information)||[:memo:](https://leetcode.com/articles/masking-personal-information/)|Medium|
|861|[flipping-an-image](https://leetcode.com/problems/flipping-an-image)||[:memo:](https://leetcode.com/articles/flipping-an-image/)|Easy|
|862|[find-and-replace-in-string](https://leetcode.com/problems/find-and-replace-in-string)||[:memo:](https://leetcode.com/articles/find-and-replace-in-string/)|Medium|
|863|[sum-of-distances-in-tree](https://leetcode.com/problems/sum-of-distances-in-tree)||[:memo:](https://leetcode.com/articles/sum-of-distances-in-tree/)|Hard|
|864|[image-overlap](https://leetcode.com/problems/image-overlap)||[:memo:](https://leetcode.com/articles/image-overlap/)|Medium|
|866|[rectangle-overlap](https://leetcode.com/problems/rectangle-overlap)||[:memo:](https://leetcode.com/articles/rectangle-overlap/)|Easy|
|867|[new-21-game](https://leetcode.com/problems/new-21-game)||[:memo:](https://leetcode.com/articles/new-21-game/)|Medium|
|868|[push-dominoes](https://leetcode.com/problems/push-dominoes)||[:memo:](https://leetcode.com/articles/push-dominoes/)|Medium|
|869|[similar-string-groups](https://leetcode.com/problems/similar-string-groups)||[:memo:](https://leetcode.com/articles/similar-string-groups/)|Hard|
|870|[magic-squares-in-grid](https://leetcode.com/problems/magic-squares-in-grid)||[:memo:](https://leetcode.com/articles/magic-squares-in-grid/)|Easy|
|871|[keys-and-rooms](https://leetcode.com/problems/keys-and-rooms)||[:memo:](https://leetcode.com/articles/keys-and-rooms/)|Medium|
|872|[split-array-into-fibonacci-sequence](https://leetcode.com/problems/split-array-into-fibonacci-sequence)||[:memo:](https://leetcode.com/articles/split-array-into-fibonacci-sequence/)|Medium|
|873|[guess-the-word](https://leetcode.com/problems/guess-the-word)||[:memo:](https://leetcode.com/articles/guess-the-word/)|Hard|

0 comments on commit 23a3f14

Please sign in to comment.