你必須很努力

刷題難度逐漸增強

2019/09/20
字數統計: 225閱讀時間: 1 min

刷 1000 題 Coderwars LV8 或 LV7
不代表有本事刷 LV1 一題
前面練習是為了更熟悉 Ruby 語法及如何使用
重點在於如何思考邏輯、解題
接下來會漸漸把強度加強
這次以 LV6、LV7 各一題


題目(Form The Minimum)

1
2
3
4
5
Task
Given a list of digits, return the smallest number that could be formed from these digits, using the digits only once (ignore duplicates).

Notes:
Only positive integers will be passed to the function (> 0 ), no negatives or zeros.

1
2
3
4
5
6
7
def min_value(digits)
# your code here
end

Test.assert_equals(min_value([1, 3, 1]), 13)
Test.assert_equals(min_value([4, 7, 5, 7]), 457)
Test.assert_equals(min_value([4, 8, 1, 4]), 148)

題目(Break camelCase)

1
2
3
4
Complete the solution so that the function will break up camel casing, using a space between words.

Example
solution('camelCasing') # => should return 'camel Casing'

1
2
3
4
5
6
def solution(string)
# complete the function
end

Test.assert_equals(solution('camelCasing'), 'camel Casing')
Test.assert_equals(solution('camelCasingTest'), 'camel Casing Test')


影片解題:


答案:

1
2
3
4
5
6
7
8
9
10
# Form The Minimum
def min_value(digits)
digits.uniq.sort.join.to_i
end


# Break camelCase
def solution(string)
string.gsub(/([A-Z])/, ' \1')
end

本文同步發布於 小菜的 Blog https://riverye.com/

原文連結:https://riverye.com/2019/09/20/刷題難度逐漸增強/

發表日期:2019-09-20

更新日期:2022-12-21

CATALOG