Leetcode
310: Minimum Height Trees
read the blog:
To be continued.
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
int, the solution creates an int variable where each bit of the variable corresponds to one of the characters in the string. Instead of reading and writing an array, the solution reads and writes the bits of the number.public static boolean isUniqueChars(String str) {
if (str.length() > 256) { // NOTE: Are you sure this isn't 26?
return false;
}
int checker = 0;
for (int i = 0; i < str.length(); i++) {
int val = str.charAt(i) - 'a';
if ((checker & (1 << val)) > 0) return false;
checker |= (1 << val);
}
return true;
}
#. _9_
/ \
3 2
/ \ / \
4 1 # 6
/ \ / \ / \
# # # # # #
"9,3,4,#,#,1,#,#,2,#,6,#,#", where# represents a null node.nums = [ [9,9,4], [6,6,8], [2,1,1] ]
4[1, 2, 6, 9].nums = [ [3,4,5], [3,2,6], [2,2,1] ]
4[3, 4, 5, 6]. Moving diagonally is not allowed.dp[i] = min(dp[i], dp[i - coins[j]] + 1);
words, find the maximum value of length(word[i]) * length(word[j])where the two words do not share common letters. You may assume that each word will contain only lower case letters. If no such two words exist, return 0.