摘要: 题目 Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: true Explanation: 20 = 1 Example 2: Input: 16 阅读全文
posted @ 2018-10-14 11:06 shinjia 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 题目 Invert a binary tree. 比如原来的树为 0 1 2 逆转后的树为 0 2 1 也就是把所有结点的左右结点互换 解法一 思路 递归 代码 解法二 思路 非递归,用树的层次遍历 代码 阅读全文
posted @ 2018-10-14 10:36 shinjia 阅读(74) 评论(0) 推荐(0) 编辑
摘要: 题目 Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and t 阅读全文
posted @ 2018-10-14 10:06 shinjia 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 题目 Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the 阅读全文
posted @ 2018-10-14 09:38 shinjia 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 题目 Reverse a singly linked list. Example: Input: 1 2 3 4 5 NULL Output: 5 4 3 2 1 NULL Follow up: A linked list can be reversed either iteratively or 阅读全文
posted @ 2018-10-14 09:11 shinjia 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 题目 Count the number of prime numbers less than a non negative number, n. Example: Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 阅读全文
posted @ 2018-10-12 11:59 shinjia 阅读(86) 评论(0) 推荐(0) 编辑
摘要: 题目 Remove all elements from a linked list of integers that have value val. Example: Input: 1 2 6 3 4 5 6, val = 6 Output: 1 2 3 4 5 解法 思路 思路不难。。。就是很繁琐 阅读全文
posted @ 2018-10-12 10:16 shinjia 阅读(90) 评论(0) 推荐(0) 编辑
摘要: 题目 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 int 阅读全文
posted @ 2018-10-12 09:26 shinjia 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 题目 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 阅读全文
posted @ 2018-10-12 08:27 shinjia 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 题目 Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Example: Input: 11 Ou 阅读全文
posted @ 2018-10-11 11:08 shinjia 阅读(92) 评论(0) 推荐(0) 编辑