This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode | |
# attr_accessor :val, :next | |
# def initialize(val) | |
# @val = val | |
# @next = nil | |
# end | |
# end | |
# @param {ListNode} head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definition for singly-linked list. | |
# class ListNode | |
# attr_accessor :val, :next | |
# def initialize(val) | |
# @val = val | |
# @next = nil | |
# end | |
# end | |
# @param {ListNode} head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer[]} nums1 | |
# @param {Integer[]} nums2 | |
# @return {Integer[]} | |
def intersect(nums1, nums2) | |
result = [] | |
nums3 = Hash.new(0) | |
nums2.each do | num | | |
nums3[num] += 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer[]} nums | |
# @return {Void} Do not return anything, modify nums in-place instead. | |
def move_zeroes(nums) | |
x = 0 | |
y = x + 1 | |
loop do | |
break if y >= nums.length | |
if nums[x] == 0 && nums[y] != 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer[]} digits | |
# @return {Integer[]} | |
def plus_one(digits) | |
( digits.join.to_i + 1 ).to_s.chars.map(&:to_i) | |
end | |
# first combine/join the array to make it one integer | |
# add ( + 1 ) | |
# split the integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @param {Integer[][]} matrix | |
# @return {Void} Do not return anything, modify matrix in-place instead. | |
def rotate(matrix) | |
matrix_length = matrix.length | |
x = 0 | |
y = 0 | |
while x < matrix_length | |
y = x | |
while y < matrix_length |