首页 > TAG信息列表 > leetcode1

leetcode1-两数之和

两数之和 暴力遍历 class Solution { public int[] twoSum(int[] nums, int target) { int n = nums.length; for(int i = 0; i < n; i++){ for(int j = i+1; j < n; j++){ if(nums[i]+nums[j] == target){

leetcode1.两数之和——学习笔记

1. 两数之和 难度简单12282收藏分享切换为英文接收动态反馈 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target  的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复

Leetcode1_两数之和I_无序数组 + Leetcode167_两数之和II_有序数组

题目描述 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案 例子: 输入:nums = [2,7

LeetCode1

解法1 class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: dit = {} for i in range(len(nums)): other = target - nums[i] if other not in dit.keys(): dit[nums[i]] = i

leetCode1每日一题 189. 旋转数组

189. 旋转数组 class Solution { public void rotate(int[] nums, int k) { if(nums.length == 0 || k == 0) return; int len = nums.length; int count = 0; /* 从数组下标为 0 的位置开始遍历,使用 count 变量来统计访问过的元素数量是

LeetCode1

1 两数之和 target - num 看Map中是否存在值,存在就返回下标 class Solution { public int[] twoSum(int[] nums, int target) { int length = nums.length; HashMap<Integer,Integer> hash = new HashMap<Integer,Integer>();//存数值与下标 for(int

Leetcode1 - 10

  1. 两数之和 class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> v; for(int i = 0;i < nums.size();i++){ for(int j = i;j < nums.size();j++){ if(i

LeetCode1错误思路

1.自己没使用map进行映射,导致vector使用sort排序后,顺序发生变化,且返回下标是变化后的下标,从而产生错误。    2.自己使用map进行映射,但是vector有两个相同元素,此处仅仅记录了第一个,无法返回对应正确下标,从而产生错误。    正确思路是使用map进行元素记录,但使得后面出现元素可

【LeetCode1】两数之和

1、题目描述 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。   示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums

LeetCode1、两数之和 (c语言实现)

题目描述: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums

leetcode1

5197. 最小绝对差 给你个整数数组 arr,其中每个元素都 不相同。 请你找到所有具有最小绝对差的元素对,并且按升序的顺序返回。   示例 1: 输入:arr = [4,2,1,3]输出:[[1,2],[2,3],[3,4]] 示例 2: 输入:arr = [1,3,6,10,15]输出:[[1,3]] 示例 3: 输入:arr = [3,8,-10,23,19,-4,-14,27]输

LeetCode1-100个人总结

1.两数之和各种不用实现的条件,很简单,粗心j的初始值写为了1,应为i+1。还有就是return直接{i,j},不必新建一个vector。 2.两数相加很有难度。主要是不了解struct链表的结构和操作,ListNode res = new ListNode(0);这个是创建新链表的标准语句,此外,本题需要一个int型sum来全程记

LeetCode1----最短无序连续子序列C实现(难度:easy)

给定一个整数数组,你需要寻找一个连续的子数组,如果对这个子数组进行升序排序,那么整个数组都会变为升序排序。 你找到的子数组应是最短的,请输出它的长度。 示例 1: 输入: [2, 6, 4, 8, 10, 9, 15] 输出: 5 解释: 你只需要对 [6, 4, 8, 10, 9] 进行升序排序,那么整个表都会变为

leetcode1. 两数之和 �

题目:  给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。   你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 示例:   给定 nums = [2, 7, 11, 15], target = 9   因为 nums

leetcode1

题目链接:https://leetcode-cn.com/problems/add-two-numbers/ 代码: 1 class ListNode: 2 def __init__(self, x, _next = None): 3 self.val = x 4 self.next = _next 5 6 7 class Solution: 8 def addTwoNumber(self, l1:ListNode, l2:ListNode) -&g

查找表_leetcode1

#coding=utf-8# 解题思路:查找表 适合只有唯一解的情况 20190302 找工作期间class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ dic = {}