查找峰值元素(多个)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)
相关问答
更多-
SignalR是一个很好的方法来做到这一点, 您可以在以下问题中详细了解这一点: 使用SignalR从wcf通知JS SignalR is a good way to do it, you can see this in detail in the following question: Use SignalR to notify from wcf to JS
-
有可能有很多方法来完成这个,但这里是我的想法。 请注意,我只包含了任意数量的字符串,您可以根据需要添加/删除。 首先,您需要某种“输入”对象,该对象将传递给包含图像和字符串值的WCF服务。 注意Images属性是一个字节数组的数组; 这是因为你可以包含多个图像。 [DataContract] public class InputObject { [DataMember] public byte[][] Images { get; set; } [DataMember] pu ...
-
是的,您需要2个具有单独合同的WCF服务,但它们可以托管在同一个站点上。 使用具有“传输安全性”的绑定配置要使用SSL的那个。 Yes you need 2 WCF services with seperate contracts, but they can be hosted onn the same site. Configure the one that you want to use SSL with a binding that has "Transport Security".
-
使用不同Structs将相关数据发送到WCF的最佳方法(Best way to send related data to WCF with different Structs)[2022-10-18]
如果我理解正确,您的设备对象可以与多个用户,UserInfo或DisplayInfo相关联,这种情况下我会将它们逻辑地分组为DeviceUser,DeviceUserInfo和DeviceDisplayInfo对象,并在其中包含User / UserInfo / DisplayInfo的IEnumerable集合。 例, DeviceUser - DeviceId (int) - Users (IEnumerable) - Make (string) - Year (int) If I und ... -
通过WCF发送数据(Sending data via WCF)[2022-08-09]
WCF可以通过许多不同的传输协议(如MSMQ和http)发送数据。 它还支持消息安全性,分布式事务和分布式系统的其他更复杂的功能。 您需要创建一个WCF服务,该服务在Visual Studio中作为模板提供。 服务器应作为独立程序os托管,作为IIS中的Web应用程序。 之后,您需要创建一个可以与服务器通信的客户端。 然而,WCF是一个庞大而复杂的框架,您不应该期望能够只抓住表面并构建系统。 你需要一些谷歌搜索,并可能从MS自己的教程开始。 如果您需要真正有用的答案,您应该更加具体地了解您的程序以及客户端和 ... -
WCF发送大量数据(WCF sending huge data)[2021-07-30]
WCF支持流式传输,允许以高效的方式将大文件传输到服务端点或从服务端点传输。 有关更多信息,请查看此文章 。 WCF supports streaming to allow large files to be transferred to/from a service endpoint in a performant fashion. Check out this article for more information. -
我们使用WCF来使用属性来定义我们的数据合同和数据方法。 基本上我们创建一个程序集来定义我们所有的类和另一个程序集,以提供WCF连接位 OPur类程序集包含一个服务类和几个消息类。 我们为我们的服务定义一个接口,并将其标记为相关的WCF标记。 这是我们的服务合同。 [ServiceContract] public interface IExampleWebService { [OperationContract] CreateAccountResponse CreateAccount(int ...
-
你可以使用你想要的任何数据技术。 但是,直到.NET 4中的实体框架4(目前处于发布候选状态),建议不要从Web服务返回实体框架实体或LINQ to SQL类。 不幸的是,这两种技术都通过网络泄露了它们的实现 - 客户端代理类将具有与数据框架使用的基类相对应的客户端类。 相反,请使用数据传输对象,该对象只具有与要传输的数据的属性一一对应的属性。 You can use whichever data technology you want. However, up to Entity Framework 4 ...
-
您可以尝试使用params关键字。 就像是: public void MyMethod(params object[] list) { // access by index like list[0] etc. } 如果需要,你可以使用int或string代替object类型。 您可以在http://msdn.microsoft.com/en-us/library/w5zay9db.aspx上阅读有关params更多信息。 You can try to use params keyword. Som ...
-
将fileupload发送到WCF(send fileupload to WCF)[2022-04-11]
我最近尝试了同样的事情但失败了。 在这种情况下最好使用js。 http://www.enfew.com/12-excellent-ajax-upload-plugins/ 如果您使用的是现代浏览器,或者使用旧版浏览器的iFrame,他们中的许多人都会使用ajax。 因此浏览器兼容性也不是问题。 我自己使用https://code.google.com/p/upload-at-click/。它非常简单易用,可以满足您的需求。 I tried the same thing recently and failed ...