摘要:
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Example 2: 题目大意: 给定一个 阅读全文
摘要:
Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example 阅读全文
摘要:
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: 题目大意: 给定一个非负数num,重复的求它的数字之和,至和为一个数字,输出该数 阅读全文
摘要:
Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example: 题目大意: 给定二叉树,输出它的所有路径,用vector容器保存。 理 解: 采用递归的思想。 阅读全文
摘要:
Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Example 2: 题目大意: 给定两个字符串,判断t是否是s的字母异位词。 理 解: 题目说明可以假设字符串 阅读全文
摘要:
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list -- head = [4,5,1,9], wh 阅读全文
摘要:
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia 阅读全文
摘要:
Given a singly linked list, determine if it is a palindrome. Example 1: Example 2: 题目大意: 判断一个单链表是否为回文链表。 理 解: 方法一:时间复杂度O(n),空间复杂度O(1) 计算链表长度,逆置前半部分链表, 阅读全文
摘要:
Given an integer, write a function to determine if it is a power of two. Example 1: Example 2: Example 3: 题目大意: 判断一个整数是否为2的幂次方。 理 解: 2的幂 的二进制表示中只有一位是1 阅读全文
摘要:
Given an integer n, return the number of trailing zeroes in n!. Example 1: Example 2: 题目大意: 给定一个整数,求它的阶乘末尾0的个数。 理 解: n的阶乘可表示为x*(10^k) = x*(2^k * 5^k)。 阅读全文