leetcode 496 Next Greater Element I
来源:互联网 发布:新闻资讯网站源码 编辑:程序博客网 时间:2024/06/07 09:14
原题:
You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.
The Next Greater Number of a number x in nums1 is the first greater number to its right in nums2. If it does not exist, output -1 for this number.
题目的意思
就是找到对应元素后面比他大的元素。
int* nextGreaterElement(int* findNums, int findNumsSize, int* nums, int numsSize, int* returnSize) { int* result; result=(int *)malloc(sizeof(int)*findNumsSize); *returnSize=findNumsSize; for(int n=0;n<findNumsSize;n++) { int flag=0; *(result+n)=-1; for(int m=0;m<numsSize;m++) { if(*(findNums+n)==*(nums+m)) { flag=1; } if(flag==1&&*(nums+m)>*(findNums+n)) { *(result+n)=*(nums+m); break; } } } return result;}就是简单的扫描。
阅读全文
0 0
- leetcode-496-Next Greater Element I
- Leetcode #496 Next Greater Element I
- leetcode[496]:Next Greater Element I
- 【LeetCode】496 Next Greater Element I
- leetcode 496 Next Greater Element I
- LeetCode 496 Next Greater Element I
- LEETCODE--Next Greater Element I
- [LeetCode] Next Greater Element I
- LeetCode:Next Greater Element I
- 【leetcode】Next Greater Element I
- LeetCode Next Greater Element I
- Next Greater Element I(leetcode)
- LeetCode-Next Greater Element I
- LeetCode 496: Next Greater Element I (下一个大的元素)
- LeetCode.496(503、556) Next Greater Element I && II && III
- 【Leetcode】496. Next Greater Element I
- leetcode -- 496. Next Greater Element I 【栈】
- 【LeetCode】496. Next Greater Element I
- 【集训】jzoj 2017.7.10 noip模拟赛A 总结
- [kotlin系列] (s1_2)基本类型
- js判断两个日期之间的天数差
- C++ 函数重载
- Spring BOOT 热部署
- leetcode 496 Next Greater Element I
- KL散度(Kullback-Leibler Divergence)
- Activity的生命周期
- 南阳OJ 852题 蛇形填数(二)
- python 格式化Json数据
- HTML5
- Siebel系统中配置LDAP认证
- WebService学习总结(一)——WebService的相关概念
- echo 懒加载