诡异的数学,数字问题 - leetcode】的更多相关文章

134. Gas Station 那么这题包含两个问题: 1. 能否在环上绕一圈? 2. 如果能,这个起点在哪里? 第一个问题,很简单,我对diff数组做个加和就好了,leftGas = ∑diff[i], 如果最后leftGas是正值,那么肯定存在这么一个起始点.如果是负值,那说明,油的损耗大于油的供给,不可能有解.得到第一个问题的答案只需要O(n). 对于第二个问题,起点在哪里? 假设,我们从环上取一个区间[i, j], j>i, 然后对于这个区间的diff加和,定义 sum[i,j] =…
好久没切 leetcode 的题了,静下心来切了道,这道题比较有意思,和大家分享下. 我把它叫做 "不一样的猜数字游戏",我们先来看看传统的猜数字游戏,Guess Number Higher or Lower.题意非常的简单,给定一个数字 n,系统会随机从 1 到 n 中抽取一个数字,你需要写一个函数 guessNumber,它的作用是返回系统选择的数字,同时你还有一个外部的 API 可以调用,是为 guess 函数,它会将你猜的数字和系统选择的数字比较,是大了还是小了. 非常的简单,…
1.利用荷兰国旗的思路,每次记住最后一个位置,遇到一个不重复的数,放在它后面,代码很简单. Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with consta…
数学篇 # 题名 刷题 通过率 难度 2 两数相加   29.0% 中等 7 反转整数 C#LeetCode刷题之#7-反转整数(Reverse Integer) 28.6% 简单 8 字符串转整数 (atoi)   15.3% 中等 9 回文数 C#LeetCode刷题之#9-回文数(Palindrome Number) 51.7% 简单 12 整数转罗马数字   53.8% 中等 13 罗马数字转整数 C#LeetCode刷题之#13-罗马数字转整数(Roman to Integer) 53…
翻译 给定一个整型数组,除了某个元素外其余的均出现了三次. 找出这个元素. 备注: 你的算法应该是线性时间复杂度. 你能够不用额外的空间来实现它吗? 原文 Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you…
You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not con…
1 题目 Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 接口: public String multiply(String num1, String num2); 2 思路 大整数的乘法,不能够简单用Integer.valueOf(…
题目:singleNumber Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 给一个数组里面除了唯一的一个数只出现一次,其他每个数都…
位运算篇 # 题名 刷题 通过率 难度 78 子集   67.2% 中等 136 只出现一次的数字 C#LeetCode刷题之#136-只出现一次的数字(Single Number) 53.5% 简单 137 只出现一次的数字 II   60.7% 中等 169 求众数 C#LeetCode刷题之#169-求众数(Majority Element) 52.2% 简单 187 重复的DNA序列   39.7% 中等 190 颠倒二进制位 C#LeetCode刷题之#190-颠倒二进制位(Rever…
字符串篇 # 题名 刷题 通过率 难度 3 无重复字符的最长子串   24.6% 中等 5 最长回文子串   22.4% 中等 6 Z字形变换   35.8% 中等 8 字符串转整数 (atoi)   15.3% 中等 10 正则表达式匹配   18.4% 困难 12 整数转罗马数字   53.8% 中等 13 罗马数字转整数 C#LeetCode刷题之#13-罗马数字转整数(Roman to Integer) 53.7% 简单 14 最长公共前缀 C#LeetCode刷题之#14-最长公共前缀…