Solved! Leetcode 1146. Snapshot Array

source: https://leetcode.com/problems/summary-ranges/description/ Snapshot Array Table of ContentsSnapshot ArrayDescriptionExample 1:Constraints:Solution Description Implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializes an array-like data structure with the given length. Initially, each element equals 0. void set(index, val) sets the element at the given index to be equal to val. int snap() takes a snapshot of ...

Map.computeIfAbsent: Write a clear and concise code

Table of ContentsHow?Method SignatureBehaviourTest Your KnowledgeReferences How? Suppose you are solving a graph problem where you have been given a 2D array of edges and you need to find the shortest path between a source and a destination node. At this point, you could create a graph from the given edges. ... public List<Integer> findShortestPath(int[][] ...

Leetcode 1056: Confusing Number

A confusing number is a number that, when rotated 180 degrees, becomes a different number with each digit valid. We can rotate the digits of a number by 180 degrees to form new digits. When 0, 1, 6, 8, and 9 are rotated 180 degrees, they become 0, 1, 9, 8, and 6, respectively.When 2, ...

Leetcode 290: Word Pattern

Given a pattern and a string s, find if s follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s. https://leetcode.com/problems/word-pattern/ class Solution { public boolean wordPattern(String pattern, String s) { String[] sArr = s.split(" "); Map<Character, String> map = new HashMap<>(); char[] pArr = pattern.toCharArray(); //if the length of ...