File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed
Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ // Time Complexity: O(n)
2+ // Space Complexity: O(1)
3+
4+ object Solution {
5+ def maxArea (height : Array [Int ]): Int = {
6+ var maxWater = 0
7+ var left = 0
8+ var right = height.length - 1
9+
10+ while (left < right) {
11+ var minHeight = height(left).min(height(right))
12+ var dist = right - left
13+ var capacity = minHeight * dist
14+ if (capacity > maxWater) {
15+ maxWater = capacity
16+ }
17+
18+ if (height(left) < height(right)){
19+ left += 1
20+ }
21+ else {
22+ right -= 1
23+ }
24+ }
25+
26+ return maxWater
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ // Time Complexity: O(s + t)
2+ // Space Comeplexity: O(s + t)
3+
4+ import scala .collection .mutable .Map
5+
6+ object Solution {
7+ def isAnagram (s : String , t : String ): Boolean = {
8+ if (s.length() != t.length())
9+ return false
10+
11+ var charCount = Map [Char , Int ]()
12+
13+ for (c <- s) {
14+ if (charCount.contains(c))
15+ charCount(c) = charCount(c) + 1
16+ else
17+ charCount += (c -> 1 )
18+ }
19+
20+ for (c <- t) {
21+ if (charCount.contains(c))
22+ charCount(c) = charCount(c) - 1
23+ else
24+ charCount += (c -> 1 )
25+ }
26+
27+ for ((_, v) <- charCount)
28+ if (v != 0 )
29+ return false
30+
31+ return true
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments