Skip to content

Commit 65bb25a

Browse files
author
0x01f7
committedOct 25, 2015
style: comment
1 parent 68934f1 commit 65bb25a

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed
 

‎algorithms/h_index.rb

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
# https://leetcode.com/problems/h-index/
22
#
3-
# Given an array of citations (each citation is a non-negative
4-
# integer) of a researcher, write a function to compute the
5-
# researcher's h-index. According to the definition of h-index
6-
# on Wikipedia: "A scientist has index h if h of his/her N papers
7-
# have at least h citations each, and the other N − h papers have
8-
# no more than h citations each."
3+
# Given an array of citations (each citation is a non-negative integer) of a
4+
# researcher, write a function to compute the researcher's h-index. According
5+
# to the definition of h-index on Wikipedia: "A scientist has index h if h of
6+
# his/her N papers have at least h citations each, and the other N − h papers
7+
# have no more than h citations each."
98
#
10-
# For example, given citations = [3, 0, 6, 1, 5], which means the
11-
# researcher has 5 papers in total and each of them had received
12-
# 3, 0, 6, 1, 5 citations respectively. Since the researcher has
13-
# 3 papers with at least 3 citations each and the remaining two
14-
# with no more than 3 citations each, his h-index is 3.
9+
# For example, given citations = [3, 0, 6, 1, 5], which means the researcher
10+
# has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations
11+
# respectively. Since the researcher has 3 papers with at least 3 citations
12+
# each and the remaining two with no more than 3 citations each, his h-index
13+
# is 3.
1514
#
16-
# Note: If there are several possible values for h, the maximum
17-
# one is taken as the h-index.
15+
# Note:
16+
#
17+
# If there are several possible values for h, the maximum one is taken as
18+
# the h-index.
19+
#
20+
# Credits:
21+
#
22+
# Special thanks to @jianchao.li.fighter for adding this problem and
23+
# creating all test cases.
1824

1925

2026
# @param {Integer[]} citations

‎algorithms/happy_number.rb

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# https://leetcode.com/problems/happy-number/
22
#
3-
# Write an algorithm to determine if a number is "happy". A happy number
4-
# is a number defined by the following process: Starting with any
5-
# positive integer, replace the number by the sum of the squares of its
6-
# digits, and repeat the process until the number equals 1 (where it
7-
# will stay), or it loops endlessly in a cycle which does not include 1.
8-
# Those numbers for which this process ends in 1 are happy numbers.
3+
# Write an algorithm to determine if a number is "happy". A happy number is a
4+
# number defined by the following process: Starting with any positive integer,
5+
# replace the number by the sum of the squares of its digits, and repeat the
6+
# process until the number equals 1 (where it will stay), or it loops
7+
# endlessly in a cycle which does not include 1. Those numbers for which this
8+
# process ends in 1 are happy numbers.
99
#
1010
# Example: 19 is a happy number
1111
#
1212
# 1^2 + 9^2 = 82
1313
# 8^2 + 2^2 = 68
1414
# 6^2 + 8^2 = 100
1515
# 1^2 + 0^2 + 0^2 = 1
16+
#
17+
# Credits:
18+
#
19+
# Special thanks to @mithmatt and @ts for adding this problem and creating
20+
# all test cases.
1621

1722

1823
# @param {Integer} n

‎algorithms/house_robber.rb

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
#
33
# You are a professional robber planning to rob houses along a street. Each
44
# house has a certain amount of money stashed, the only constraint stopping
5-
# you from robbing each of them is that adjacent houses have security
6-
# system connected and it will automatically contact the police if
7-
# two adjacent houses were broken into on the same night.
5+
# you from robbing each of them is that adjacent houses have security system
6+
# connected and it will automatically contact the police if two adjacent
7+
# houses were broken into on the same night.
88
#
9-
# Given a list of non-negative integers representing the amount of money
10-
# of each house, determine the maximum amount of money you can rob
11-
# tonight without alerting the police.
9+
# Given a list of non-negative integers representing the amount of money of
10+
# each house, determine the maximum amount of money you can rob tonight
11+
# without alerting the police.
12+
#
13+
# Credits:
14+
#
15+
# Special thanks to @ifanchu for adding this problem and creating all
16+
# test cases. Also thanks to @ts for adding additional test cases.
1217

1318

1419
# @param {Integer[]} nums

‎algorithms/house_robber_ii.rb

+12-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22
#
33
# This is an extension of "House Robber".
44
#
5-
# After robbing those houses on that street, the thief has found himself
6-
# a new place for his thievery so that he will not get too much attention.
7-
# This time, all houses at this place are arranged in a circle. That means
8-
# the first house is the neighbor of the last one. Meanwhile, the security
9-
# system for these houses remain the same as for those in the previous street.
5+
# After robbing those houses on that street, the thief has found himself a new
6+
# place for his thievery so that he will not get too much attention. This time,
7+
# all houses at this place are arranged in a circle. That means the first
8+
# house is the neighbor of the last one. Meanwhile, the security system for
9+
# these houses remain the same as for those in the previous street.
1010
#
11-
# Given a list of non-negative integers representing the amount of money
12-
# of each house, determine the maximum amount of money you can rob tonight
11+
# Given a list of non-negative integers representing the amount of money of
12+
# each house, determine the maximum amount of money you can rob tonight
1313
# without alerting the police.
14+
#
15+
# Credits:
16+
#
17+
# Special thanks to @Freezen for adding this problem and creating all
18+
# test cases.
1419

1520

1621
# @param {Integer[]} nums

0 commit comments

Comments
 (0)
Please sign in to comment.