
数学
_Gray
这个作者很懒,什么都没留下…
展开
-
4. 寻找两个有序数组的中位数
给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。你可以假设 nums1 和 nums2 不会同时为空。示例 1:nums1 = [1, 3]nums2 = [2]则中位数是 2.0示例 2:nums1 = [1, 2]nums2 = [3, 4]则中...原创 2019-02-02 08:24:12 · 356 阅读 · 0 评论 -
8. 字符串转换整数 (atoi)
请你来实现一个 atoi 函数,使其能将字符串转换成整数。首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号;假如第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。该字符串除了有效的整数部分之后也可能会存在多余的字符,这些字符可...原创 2019-02-03 05:49:46 · 117 阅读 · 0 评论 -
7. 整数反转
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。示例 1:输入: 123输出: 321 示例 2:输入: -123输出: -321示例 3:输入: 120输出: 21注意:假设我们的环境只能存储得下 32 位的有符号整数,则其数值范围为 [−231, 231 − 1]。请根据这个假设,如果反转后整数溢出那么就返回 0。...原创 2019-02-03 05:55:54 · 94 阅读 · 0 评论 -
1081 Rational Sum (20 分)
Given N rational numbers in the form numerator/denominator, you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts with a positive int...原创 2019-02-21 14:47:22 · 160 阅读 · 0 评论 -
1105 Spiral Matrix (25 分)
This time your job is to fill a sequence of N positive integers into a spiral matrix in non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in...原创 2019-02-21 15:03:01 · 217 阅读 · 0 评论 -
1001 A+B Format (20 分)
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specification:Each input ...原创 2019-02-10 23:09:34 · 123 阅读 · 0 评论 -
9. 回文数
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。示例 1:输入: 121输出: true示例 2:输入: -121输出: false解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。示例 3:输入: 10输出: false解释: 从右向左读, 为 01 。因此它不是一个回文...原创 2019-02-11 02:34:20 · 91 阅读 · 0 评论 -
991. 坏了的计算器
在显示着数字的坏计算器上,我们可以执行以下两种操作:双倍(Double):将显示屏上的数字乘 2; 递减(Decrement):将显示屏上的数字减 1 。最初,计算器显示数字 X。返回显示数字 Y 所需的最小操作数。 示例 1:输入:X = 2, Y = 3输出:2解释:先进行双倍运算,然后再进行递减运算 {2 -> 4 -> 3}.示例 2:...原创 2019-02-11 23:47:21 · 276 阅读 · 0 评论