查找峰值元素(多个)SWIFT(Find peak elements (multiple) SWIFT)
我将如何在数组中找到多个峰?
给定数组:[1,2,3,4,5,4,3,2,3,4,5,6,5,4,3,2,4,2]我可以使用代码找到最大峰值下面。
func findPeakElement(_ readings: [Int]) -> Int { if readings.count == 0 { return 0 } while left < right { middle1 = (left + right) / 2 middle2 = middle1 + 1 if readings[middle1] < readings[middle2] { left = middle2 } else { right = middle1 } } return left }
然而; 我需要找到所有的高峰; [5,6,4]我需要什么代码? 即使它只是告诉我峰值的数量(3)就足够了。
how would i find multiple peaks in an array?
given the array: [1,2,3,4,5,4,3,2,3,4,5,6,5,4,3,2,4,2] i can find the max peak using the code below.
func findPeakElement(_ readings: [Int]) -> Int { if readings.count == 0 { return 0 } while left < right { middle1 = (left + right) / 2 middle2 = middle1 + 1 if readings[middle1] < readings[middle2] { left = middle2 } else { right = middle1 } } return left }
however; i need to find ALL the peaks ;[5,6,4] what code would i need for this? even if it just told me the number of peaks (3) it would be enough.
原文:https://stackoverflow.com/questions/48235912
满意答案
如果我理解正确,您的设备对象可以与多个用户,UserInfo或DisplayInfo相关联,这种情况下我会将它们逻辑地分组为DeviceUser,DeviceUserInfo和DeviceDisplayInfo对象,并在其中包含User / UserInfo / DisplayInfo的IEnumerable集合。
例,
DeviceUser - DeviceId (int) - Users (IEnumerable<User>) - Make (string) - Year (int)
If I understand right, your device object can be associated with multiple Users, UserInfo's or DisplayInfo's, which case I would logically group them as DeviceUser, DeviceUserInfo and DeviceDisplayInfo objects and have a IEnumerable collection of the User / UserInfo / DisplayInfo inside it.
Example,
DeviceUser - DeviceId (int) - Users (IEnumerable<User>) - Make (string) - Year (int)
相关问答
更多从WCF发送信息到JavaScript(Send information from the WCF to JavaScript)
将多个文件发送到WCF服务的最佳方式是什么?(What is the best way to send multiple files to a WCF service?)
需要保护WCF数据,但仅限于一个部分(Need to secure WCF data, but just for one section)
使用不同Structs将相关数据发送到WCF的最佳方法(Best way to send related data to WCF with different Structs)
通过WCF发送数据(Sending data via WCF)
WCF发送大量数据(WCF sending huge data)
WCF:将表单数据发送到Web服务的最佳实践?(WCF: Best practice to send Form Data to a Web Service?)
WCF。(WCF. to send data through service and client)
WCF:发送多个具有相同名称的参数(WCF : send multiple params with same name)
将fileupload发送到WCF(send fileupload to WCF)
相关文章
更多千锋首发Swift视频教程
Swift入门视频教程-尚学堂视频教程
Solr4:Tomcat7与Solr之多核配置(Multiple Cores)
学习di'z地址
Hadoop配置多个硬盘
HTML5 Audio元素【HTML5教程 - 第五篇】
Prince Of Persia III - The Two Thrones 通关完成
Hadoop下运行多个SecondaryNameNode的配置
could not find system property or JNDI
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!