随笔分类 -  Numbers & Digits

摘要:Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element. We define an array is non-decr 阅读全文
posted @ 2019-04-29 13:19 北叶青藤 阅读(189) 评论(0) 推荐(0)
摘要:Given an integer n, return 1 - n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9]. Please optimize your algori 阅读全文
posted @ 2017-01-09 11:40 北叶青藤 阅读(192) 评论(0) 推荐(0)
摘要:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total 阅读全文
posted @ 2017-01-03 10:07 北叶青藤 阅读(284) 评论(0) 推荐(0)
摘要:The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calcul 阅读全文
posted @ 2017-01-03 09:58 北叶青藤 阅读(229) 评论(0) 推荐(0)
摘要:Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once. Find all the elements that appear twi 阅读全文
posted @ 2016-12-30 11:03 北叶青藤 阅读(178) 评论(0) 推荐(0)
摘要:Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion? 阅读全文
posted @ 2016-12-29 01:19 北叶青藤 阅读(155) 评论(0) 推荐(0)
摘要:Determine whether an integer is a palindrome. Do this without extra space. 分析:把一个数倒过来,然后看两个数是否相同。 Reverse digits of an integer. Example1: x = 123, ret 阅读全文
posted @ 2016-12-29 00:15 北叶青藤 阅读(235) 评论(0) 推荐(0)
摘要:Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n]inclusive can be form 阅读全文
posted @ 2016-10-16 12:03 北叶青藤 阅读(244) 评论(0) 推荐(0)
摘要:Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. 阅读全文
posted @ 2016-10-11 11:09 北叶青藤 阅读(323) 评论(0) 推荐(0)
摘要:Strobogrammatic Number I A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function t 阅读全文
posted @ 2016-10-10 08:48 北叶青藤 阅读(310) 评论(0) 推荐(0)
摘要:Construct minimum number by reordering a given non-negative integer array. Arrange them such that they form the minimum number. Notice The result may 阅读全文
posted @ 2016-09-15 02:01 北叶青藤 阅读(376) 评论(0) 推荐(0)
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating 阅读全文
posted @ 2016-08-08 11:39 北叶青藤 阅读(331) 评论(0) 推荐(0)
摘要:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. For example:Given n = 13,Return 阅读全文
posted @ 2016-08-07 11:48 北叶青藤 阅读(233) 评论(0) 推荐(0)
摘要:Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is tha 阅读全文
posted @ 2016-08-06 11:19 北叶青藤 阅读(219) 评论(0) 推荐(0)
摘要:Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => true Note: It is intended for the 阅读全文
posted @ 2016-08-05 23:11 北叶青藤 阅读(264) 评论(0) 推荐(0)
摘要:Factor Combinations Problem: Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a function that takes an in 阅读全文
posted @ 2016-08-05 03:25 北叶青藤 阅读(213) 评论(0) 推荐(0)
摘要:Additive number is a string whose digits can form additive sequence. A valid additive sequence should contain at least three numbers. Except for the f 阅读全文
posted @ 2016-08-04 09:12 北叶青藤 阅读(194) 评论(0) 推荐(0)
摘要:Missing Ranges You are given an inclusive range [lower, upper] and a sorted unique integer array nums, where all elements are in the inclusive range. 阅读全文
posted @ 2016-08-03 08:27 北叶青藤 阅读(194) 评论(0) 推荐(0)
摘要:Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 阅读全文
posted @ 2016-08-03 07:19 北叶青藤 阅读(170) 评论(0) 推荐(0)
摘要:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every 阅读全文
posted @ 2016-08-02 12:59 北叶青藤 阅读(184) 评论(0) 推荐(0)