【LeetCode從零單刷】Single Number,leetcodesingle沒錯我就是伍聲2009的粉絲,從今天起,模仿《從零單排》系列,菜雞單刷LeetCode!題目:Given an array of integers, every element appears twice except for one. Find that single one.解答:其實就是找不同。這題需要一個比較trick的思路:位元運算。試想,任何兩個相同的數,進行異或操作答案是啥?是0. 4^8
LeetCode Subsets,leetcodesubsetsGiven a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,If S = [1,2
LeetCode OJ Number of Islands,leetcodeojGiven a 2d grid map of '1's (land) and'0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all
[LeetCode] Min Stack Min Stack,leetcodeminstackMin StackDesign a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() --
Pascal's Triangle II--LeetCode,pascalstriangleii 題目:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use
Perfect hashing (And Minimal perfect hashing),hashingminimalPerfect Hashing:A hash function that is injective—that is, maps each valid input to a different hash value—is said to be perfect. With such a function one can directly locate the