题目描述:
LeetCode 422. Valid Word Square
Given a sequence of words, check whether it forms a valid word square.
A sequence of words forms a valid word square if the kth row and column read the exact same string ...
LeetCode 422. Valid Word Square
Given a sequence of words, check whether it forms a valid word square.
A sequence of words forms a valid word square if the kth row and column read the exact same string ...
LeetCode 421. Maximum XOR of Two Numbers in an Array
Given a list of numbers, a[0], a[1], a[2], … , a[N-1], where 0 <= a[i] < 2^32. Find the maximum result of a[i ...
LeetCode 419. Battleships in a board
Given an 2D board, count how many different battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules ...
Java中遍历HashMap对象中的条目(Entry)时,通常有两种方式:
下面的测试分别采用KeySet和EntrySet,通过forEach遍历同一个HashMap对象中的条目。
测试结果表明,方法2通过EntrySet遍历效率优于方法1通过KeySet遍历。
Java代码:
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestMapTraversal {
private static int MAXCOUNT = 3000000 ...
LeetCode 414. Third Maximum Number
Given an array of integers, return the 3rd Maximum Number in this array, if it doesn't exist, return the Maximum Number. The time complexity must be O(n) or less.
给定一个整数数组,返回数组中第3大的数,如果不存在 ...