Week 4 of Practicing Leetcode

#find even digits# @param {Integer[]} nums# @return {Integer}def find_numbers(nums)nums.count { |x| x.digits.size.even? }end
#remove outermost parenthesis# @param {String} s# @return {String}def remove_outer_parentheses(s)counter = 0output = Array.news.split(//).each do |c|output << c unless (counter == 0 && c == "(") || (counter == 1 && c == ")")counter += 1 if c == "("counter -= 1 if c == ")"endoutput.joinend
#final price w/ discount# @param {Integer[]} prices# @return {Integer[]}def final_prices(prices)output = []new_a = []for i in 0...prices.size - 1min = nilprices[i+1..-1].select{|v| break min = v if v <= prices[i]}min.nil? ? output << prices[i] : output << prices[i] - minendoutput << prices[-1]p outputend
#self dividing mumbers# @param {Integer} left# @param {Integer} right# @return {Integer[]}def self_dividing_numbers(left, right)result = [](left..right).each { |num| result << num if num.to_s.chars.all? { |digit| digit != '0' and num % digit.to_i == 0 }}return resultend
#number of students doing homework# @param {Integer[]} start_time# @param {Integer[]} end_time# @param {Integer} query_time# @return {Integer}def busy_student(start_time, end_time, query_time)start_time.each_with_index.map { |st, i| st <= query_time && end_time[i] >= query_time ? 1 : 0 }.sumend




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Timery — Friendly Timer

Kyve Testnet Pool Delegating

Migrating to ExoPlayer 2.9.0

what is Replication and Sharding??

Importing Data from InfluxDB to Tableau Desktop

Gitlab CI/CD Crash Course and Development Strategies


Eclipse Luna For Mac Sierra

Memory Leak, Explain it to me like I’m 5.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parker Williamson

Parker Williamson

More from Medium

CS373 Spring 2022: Christopher Carrasco — Week 11

I Promised Myself…. and Then Broke the Promise 54 Years Later

The Money Interview #1

Are You In That Career or Business for The Right Reasons?