Given two 1d vectors, implement an iterator to return their elements alternately. For example, given two 1d vectors: v1 = [1, 2] v2 = [3, 4, 5, 6] By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1, 3, 2, 4, 5, 6]. Follow up: What if…

# Java

### Java, LeetCode

# [LeetCode] Search in Rotated Sorted Array II

## by 达达主义 • • 0 Comments

Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists…

### Java, LeetCode

# [LeetCode] Search in Rotated Sorted Array

## by 达达主义 • • 0 Comments

Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its index, otherwise return -1. You may assume no duplicate exists…

### Java, LeetCode

# [LeetCode] Single Number

## by 达达主义 • • 0 Comments

Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? [思路] [常见错误] 1. [Code] public class Solution { public int singleNumber(int[] A) { final int undef = -999; int i, j; //…

### Java, LeetCode

# [LeetCode] Remove Element

## by 达达主义 • • 0 Comments

Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn’t matter what you leave beyond the new length. [思路] 注意题目要求，是要”in place”。可以使用”two pointers”的方法，遍历数组一遍。 [常见错误] 1. 注意数组为空的特殊情况 [Code] public class Solution { public int removeElement(int[] A, int elem) {…