自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(10)
  • 收藏
  • 关注

原创 LeetCode 167. Two Sum II - Input array is sorted

1.题目2.题意已经排序的数组,查找两数之和为给定值,返回这两个数的次序3.我的解法/** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */int* twoSum(int* numbers, int number...

2018-05-13 15:03:26 214 1

原创 LeetCode 122. Best Time to Buy and Sell Stock II

1.题目2.题意与121 购买股票的题目类似,不过这次允许多次购买3.我的解法int maxProfit(int* prices, int pricesSize) { int max=0; int i; for (i=1;i<pricesSize;i++){ if(prices[i]>prices[i-1]){ max+=...

2018-05-12 15:03:30 106

原创 LeetCode 121.Best Time to Buy and Sell Stock

1.题目2.题意给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润。注意你不能在买入股票前卖出股票。3.我的解法int maxProfit(int* prices, int pricesSize) { int i,j,max; int Max=0; for (i=0;i...

2018-05-12 14:46:34 112

原创 LeetCode 53.Maximum Subarray

1.题目2.题意求最大子序列,follow up要求采用分治法3.我的解法int maxSubArray(int* nums, int numsSize) { int ans=nums[0],i,sum=0; for (i=0;i<numsSize;i++){ sum+=nums[i]; if(ans<sum)ans=sum; ...

2018-05-11 16:09:37 152

原创 LeetCode 66.Plus One

1.题目2.题意给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组。3.我的解法/** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */int* plusOne(int* digits, int...

2018-05-11 15:38:21 160

原创 LeetCode 88.Merge Sorted Array

1.题目2.题意             给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组。3.我的解法void merge(int* nums1, int m, int* nums2, int n) { int ptr1,ptr2,ptr,i; ptr=ptr1=ptr2=0; int snum;...

2018-05-11 15:15:34 152

原创 LeetCode 35.Search Insert Position

1.题目2.题意给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。3.我的解法int searchInsert(int* nums, int numsSize, int target) { int fro,end,mid; fro=0; end=numsSize-1; while(fro<=...

2018-05-10 09:04:50 79

原创 LeetCode 27.Remove Element

1.题目2.题意原地移除所有数值等于 val 的元素,返回移除后数组的新长度和新数组3.我的解法int removeElement(int* nums, int numsSize, int val) { int i; int len=0; for (i=0;i<numsSize;i++){ if(nums[i]!=val){ ...

2018-05-10 08:48:37 100

原创 LeetCode 26.Remove Duplicates from Sorted Array

1.题目2.题意给了一个排好序的数组,要求返回不重复的数组长度length,并使数组前length个为不重复的元素,且不使用额外空间3.我的解法int removeDuplicates(int* nums, int numsSize) { /*for循环控制外层的跳转,每次加的不是1,而是key+1,key标识每次重复的长度,这样可以减少遍历次数,不用每个都来一遍 len标识真正长度,再将不重...

2018-05-09 10:54:15 96

原创 LeetCode1.Two Sum

1.题目2.题意返回相加的两数等于特定值的索引3.我的解法   /** * Note: The returned array must be malloced, assume caller calls free(). */int* twoSum(int* nums, int numsSize, int target) { int *a = (int*)malloc(2*sizeof(...

2018-05-09 10:30:59 181

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除