LeetCode in Ruby (11 Part Series)
This approach is based on Ruby’s
String#count method. It takes the string
j as the set of characters to count in the string
s. This is the fastest and the simplest solution.
def num_jewels_in_stones(j, s) stones = Hash.new 0 s.each_char do |char| stones[char] += 1 end sum = 0 j.each_char do |char| sum += stones[char] end return sum end
First, we iterate through the string
s and create a hash called
stones that uses the characters in
s as keys and their occurrence as values. Then we go through each character of
j and sum up their occurrences.
(open source and trusted by devs everywhere ❤️)
Throughout the last year, I have worked part-time as a working student and also studied at the university. I was not the first and not the last one who has combined that during their studies, but the problem for me was, that at the end of the day I have felt absolutely exhausted mentally and physically. That caused problems with my health and motivation to continue working on my goals or anything. (yeah, “goals,” I wish I had something more specific at that time).