wangyw Blog

Constant dropping wears the stone

leetcode 202. Happy Number

leetcode 202. Happy Number 题意 Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the...

leetcode 22. Generate Parentheses

leetcode 22. Generate Parentheses 题意 Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example given n = 3, a solution set is: ”((()))”...

leetcode 230. Kth Smallest Element in a BST

leetcode 230. Kth Smallest Element in a BST 题意 Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ B...

leetcode 99. Recover Binary Search Tree

leetcode 99. Recover Binary Search Tree 题意 Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space...

leetcode 108. Convert Sorted Array to Binary Search Tree

leetcode 108. Convert Sorted Array to Binary Search Tree 题意 Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Subscribe to see which companies ask...

n&(n-1) 的用法

n&(n-1) 的用法 求某一个数的二进制表示中1的个数 while (n >0 ) { count ++; n &= (n-1); } 判断一个数是否是2的方幂 n > 0 && ((n & (n - 1)) == 0 ) 计算N!的质因数2的个数。 容易得出N!质因数2...

Lowest Common Ancestor of Tree

Lowest Common Ancestor of Tree leetcode235. Lowest Common Ancestor of a Binary Search Tree Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. ...

leetcode328. Odd Even Linked List

leetcode328. Odd Even Linked List 题意 Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value i...

House Robber

House Robber 198. House Robber You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing...

Flatten Nested List Iterator

341. Flatten Nested List Iterator 题意 Given a nested list of integers, implement an iterator to flatten it. Each element is either an integer, or a list – whose elements may also be integers or o...