ICode9

精准搜索请尝试: 精确搜索
  • LeetCode 1:Two Sum2019-06-05 13:42:06

    C语言: /** * Note: The returned array must be malloced, assume caller calls free(). */int* twoSum(int* nums, int numsSize, int target, int* returnSize){ int i, j; int *result = (int*)malloc(2 * sizeof(int)); *returnSize = 2; for(i=0; i < num

  • 原地算法2019-05-24 18:51:07

    在只使用O(1)的的额外空间的情况下在原地修改输入数组. 例如: 给定nums=[0,0,1,1,1,2,2,3,3,4],删去重复的元素,返回长度为5,元素为[0,1,2,3,4]; 函数代码实现为: int removeDuplicates(int* nums, int numsSize) //原地算法 { int i; if (nums == NULL || numsSize ==

  • 两数之和2019-04-14 09:39:53

    1 /* 2  * Note: The returned array must be malloced, assume caller calls free(). 3  */ 4 int* twoSum(int* nums, int numsSize, int target) { 5     static int a[2] = {0};     6     for (int i = 0; i < numsSize - 1; i++) { 7         for (int j = i +

  • LeetCode新手刷题记——关于两数之和的思考2019-04-04 16:52:55

    首先是题目描述: 拿到这个问题我的脑子里就有了一个邪恶的想法——暴力穷举。 于是我使用了c语言按照自己的想法写了一个template,结果执行的时候出现了一堆问题,我也不知道哪有问题,于是就看评论区别人的答案,然后照着改就对。 int* twoSum(int* nums, int numsSize, int target)

  • leetcode刷题日记之搜索插入位置2019-03-17 18:40:56

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。 你可以假设数组中无重复元素。 注意:有序数组基本都可以用二分法或首位扫描法。 在这里,我第一次用的双指针发,但是出错,所以改用首位扫描法。注意在扫描时不能

  • 【基础层】##编程##练习##LeetCode## 35. Search Insert Position2019-03-13 13:51:10

      35. Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array. Example 1: Input: [1,3,5,6]

  • LeetCode01:两数之和2019-03-10 09:44:30

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

  • LeetCode刷题:第一题 两数之和2019-03-09 16:42:14

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

  • 至少是其他数字两倍的最大数——力扣2019-03-04 21:00:33

    在一个给定的数组nums中,总是存在一个最大元素 。 查找数组中的最大元素是否至少是数组中每个其他数字的两倍。 如果是,则返回最大元素的索引,否则返回-1。 示例 1: 输入: nums = [3, 6, 1, 0]输出: 1解释: 6是最大的整数, 对于数组中的其他整数,6大于数组中其他元素的两倍。6的索引是

  • 【LeetCode】414. 第三大的数2019-03-03 21:50:00

    给定一个非空数组,返回此数组中第三大的数。如果不存在,则返回数组中最大的数。要求算法时间复杂度必须是O(n)。 示例 1: 输入: [3, 2, 1] 输出: 1 解释: 第三大的数是 1. 示例 2: 输入: [1, 2] 输出: 2 解释: 第三大的数不存在, 所以返回最大的数 2 . 示例 3: 输入: [2, 2, 3, 1

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有