【easy】268. Missing Number】的更多相关文章

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1 Input: [3,0,1] Output: 2 Example 2 Input: [9,6,4,2,3,5,7,0,1] Output: 8 用异或的办法: class Solution { public: int missingNumber…
Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example,Given nums = [0, 1, 3] return 2. Note:Your algorithm should run in linear runtime complexity. Could you i…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 求和 异或 日期 题目地址:https://leetcode.com/problems/missing-number/#/description 题目描述 Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is miss…
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 number by the sum of the squares of its digits, and repeat the proc…
class Solution { public: bool isUgly(int num) { ) return false; ) return true; && num % == ) num /= ; && num % == ) num /= ; && num % == ) num /= ; ; } }; 所谓丑数,是指质因子只能是2,3,5中的.1认为也是丑数.…
题目如下: 解题思路:题目很简单.先对数组排序,根据最大值和最小值即可求出公差,然后遍历数组,计算相邻元素的差,如果差不等于公差,即表示数字缺失. 代码如下: class Solution(object): def missingNumber(self, arr): """ :type arr: List[int] :rtype: int """ arr.sort() diff = (arr[-1] - arr[0])/(len(arr)) fo…
181. Flip Bits[easy] Determine the number of bits required to flip if you want to convert integer n to integer m. Notice Both n and m are 32-bit integers. Example Given n = 31 (11111), m = 14 (01110), return 2. 解法一: class Solution { public: /** *@par…
170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should support the following operations:add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum…
88. Merge Sorted Array[easy] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.…
605. Can Place Flowers[easy] Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die. Given a flowerbed (represe…