## Code ```java= class Solution { public List<Integer> relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) { Set<Integer> marbles = new HashSet<>(); for(int num:nums) marbles.add(num); for(int i=0; i<moveFrom.length; i++){ if(marbles.contains(moveFrom[i])){ marbles.remove(moveFrom[i]); marbles.add(moveTo[i]); } } List<Integer> ans = new ArrayList<>(marbles); Collections.sort(ans); return ans; } } ``` ```python= class Solution: def relocateMarbles(self, nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]: s = set(nums) for f, t in zip(moveFrom, moveTo): s.remove(f) s.add(t) return sorted(s) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up