Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 536 Bytes

Question_2154.md

File metadata and controls

24 lines (19 loc) · 536 Bytes

LeetCode Records - Question 2154 Keep Multiplying Found Values by Two

Attempt 1: Use a HashSet, a for loop, and a while loop

class Solution {
    public int findFinalValue(int[] nums, int original) {
        Set<Integer> set = new HashSet<>();

        for (int num : nums) {
            set.add(num);
        }

        while (set.contains(original)) {
            original *= 2;
        }

        return original;
    }
}
  • Runtime: 3 ms (Beats: 67.17%)
  • Memory: 44.30 MB (Beats: 14.55%)