/leetcode-scala

My solutions in Scala to some Leetcode problems, for familiarizing myself with Scala.

Primary LanguageScala

Solutions in Scala to Leetcode Problems

Familiarizing myself with Scala language using Leetcode problems, and these are my solutions.

Quiz Name My Solution Keywords
811.Subdomain Visit Count solution for...yield, Tuple, groupBy, mapValues
819.Most Common Word solution Regular Expression, groupBy, maxBy
121.Best Time to Buy and Sell Stock solution for-loop, if-else
551.Student Attendance Record I solution Boolean
268.Missing Number solution filter
476.Number Complement solution Parse Integer
821.Shortest Distance to a Character solution map, filter, min, abs
389.Find the Difference solution distinct, filter, ! (NOT), contains (similar to in in Python)
561.Array Partition I solution Sort an Array (or List), sum
784.Letter Case Permutation solution Regular Expression, def (function), toUpperCase, toLowerCase, for...yield
657.Judge Route Circle solution map, filter, & (AND)
136.Single Number solution distinct, filter
804.Unique Morse Code Words solution Map, Map.getOrElse, for...yield, distinct, Concatenate Strings
412.Fizz Buzz solution def (function), % (modulus operator), if-else
520.Detect Capital solution toUpper (for Char), toUpperCase (for String), toLowerCase, OR operator, if-else, drop (string)
Implement a Hash Set solution Class, Array Concatenation, List Concatenation, contains, function
202.Happy Number solution (Mutable) Set, While Loop, scala.math.pow() (exponentiation), Type Change among Int, String, Char
1.Two Sum solution (mutable) HashMap, While Loop
205.Isomorphic Strings solution (mutable) HashMap, if-else, filter, char to Int, distinct, zip
599.Minimum Index Sum of Two Lists solution (mutable) HashMap, zip, contains method (in Map), Array Concatenation
387.First Unique Character in a String solution ArrayBuffer, (mutable) HashMap, zipWithIndex, Map.retain
49.Group Anagrams solution ListBuffer, HashMap
36.Valid Sudoku solution break (control flow), self-define function, Array.distinct, Array Slicing [Array.slice()], flatMap
830.Positions of Large Groups solution ListBuffer, for-loop, if-else
831.Masking Personal Information solution findAllIn (Regular Expression), Array.mkString (merge a list of Chars into a String), Array.slice(), String.split()
824.Goat Latin solution String.split, String.toUpperCase, self-defined function, List.exists (check if there is any element meeting a specific condition), String.startsWith, zipWithIndex, List.mkString (merge a list of Chars into a String)
832.Flipping an Image solution Array.map, Array.reverse
833.Find And Replace in String solution Array.zip, Array(tuple).sortBy, Array.sorted, String.substring (string slicing), String.replaceFirst, Array.mkString
825.Friends Of Appropriate Ages solution Array.sorted, Array.reverse, Array.zipWithIndex, while loop
841.Keys and Rooms solution collection.mutable.ArrayBuffer, function/method, Recursion, distinct, contains
844.Backspace String Compare solution collection.mutable.ArrayBuffer, function/method, ArrayBuffer.remove, make a string from a list of Characters, stack
806.Number of Lines To Write String solution zip, Vector.toMap
617.Merge Two Binary Trees solution recursion, binary tree
226.Invert Binary Tree solution pattern matching, recursion, binary tree
100.Same Tree solution recusion, binary tree
572.Subtree of Another Tree solution recursion, binary tree
199.Binary Tree Right Side View solution recursion, binary tree, ArrayBuffer, groupBy, sortBy, List.last
606.Construct String from Binary Tree solution recursion, if-else, String Interpolation (String Format)
101.Symmetric Tree solution Methods with the same name for different arguments, Use Option to allow null values, recursion, groupBy, Map.mapValues, forall, ArrayBuffer
55.Jump Game solution while, if-else
744.Find Smallest Letter Greater Than Target solution collection.exists, collection.filter, collection.min
26.Remove Duplicates from Sorted Array solution two-pointer
7.Reverse Integer solution math.abs, collection.slice, collection.zipWithIndex, collection.find, Some(*).get, try-catch, String.reverse
94.Binary Tree Inorder Traversal solution recursion, mutable.ArrayBuffer, Binary Tree
230.Kth Smallest Element in a BST solution recursion, Binary Search Tree
669.Trim a Binary Search Tree solution recursion, Binary Search Tree, if-else
108.Convert Sorted Array to Binary Search Tree solution Binary Search Tree, Recursion
538.Convert BST to Greater Tree solution Binary Search Tree, Recursion
515.Find Largest Value in Each Tree Row solution Tree, Recursion, collection.sortBy, collection.mutable.HashMap
697.Degree of an Array solution ArrayBuffer, collection.mutable.HashMap, zipWithIndex, Map.contains(), collection.last, collection.head, collection.min & .max
53.Maximum Subarray solution
848.Shifting Letters solution Conversion between Char and Int
504.Base 7 solution math.abs, Modulo operatio (%), while-loop, if-else, List.reverse
747.Largest Number At Least Twice of Others solution collection.sorted, collection.indexOf (find the index of an element in a list)
733.Flood Fill solution Recursion, format string
781.Rabbits in Forest solution collection.toSet, math.ceil, collection.count
884.Uncommon Words from Two Sentences solution Set Operations, Map
941.Valid Mountain Array solution if-else