![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
lintcode刷题
我就是个five
辣鸡考研er
展开
-
不用‘+’号求 a+b 小白创作 错误请指出 轻喷!!!
class Solution {public: int aplusb(int a, int b) { while(b != 0){ int up= a & b; a = a ^ b; b = (up << 1); } return a; }}; 之前没有看过位运,...原创 2018-05-18 09:03:36 · 199 阅读 · 0 评论 -
1:从排序数组中删除重复项(python)
nums=[1,2,3,3,3,5] j = 0 //定义以一个下标j 用它来存放数组不相同的元素 for i in range(len(nums)): if nums[i] != nums[j]: //如果不相等 ,数组 j+1下标就把 那个不相等的数存起来,这样就是实现了 删除重复项 nums[j+1] = ...原创 2019-03-24 13:14:20 · 200 阅读 · 0 评论 -
2:买卖股票的最佳时机 II(python)
def maxProfit(prices): """ :type prices: List[int] :rtype: int """ profit = 0 i = 0 while i < len(prices) - 1: if prices[i+1] > prices[i]: prof...原创 2019-03-24 13:27:35 · 280 阅读 · 0 评论 -
3: 旋转数组(python)
class Solution(object): def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: None Do not return anything, modify nums in-place instead. ...原创 2019-03-24 14:06:05 · 158 阅读 · 0 评论 -
9:两数之和(python)
def twoSum(nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ # 创建一个空字典 键为需要值,值为下标 d = {} for x in range(len(nums)): a = target -...原创 2019-03-24 15:02:01 · 423 阅读 · 0 评论 -
5:只出现一次的数字
def singleNumber(): """ :type nums: List[int] :rtype: int """ nums = [1,3,3,5,5] print(2*sum(set(nums))-sum(nums)) if __name__ == '__main__': singleNumber() 很好理解, 2*...原创 2019-03-24 15:09:20 · 157 阅读 · 0 评论