博客
关于我
Objective-C实现greedy coin change贪心硬币找零算法(附完整源码)
阅读量:795 次
发布时间:2023-02-19

本文共 1255 字,大约阅读时间需要 4 分钟。

Objective-C实现贪心硬币找零算法

贪心硬币找零算法实现

以下是一个使用Objective-C实现贪心硬币找零算法的详细示例代码:
                #import 
NSArray *greedyCoinChange(NSArray *coinValues, int amount) { NS MutableDictionary *coins = [NS MutableDictionary dictionaryWithValues:coinValues]; int remaining = amount; int index = 0; while (remaining > 0) { if (index >= [coinValues count]) { return nil; } NSDecimal *currentCoinValue = [coinValues[index] decimalValue]; if (remaining >= currentCoinValue) { [coins setValue:remaining - currentCoinValue forKey:[coinValues[index] stringValue]]; remaining -= [currentCoinValue intValue]; } else { index++; } } return coins; }

转载地址:http://ovnfk.baihongyu.com/

你可能感兴趣的文章
Netty框架的服务端开发中创建EventLoopGroup对象时线程数量源码解析
查看>>
Netty源码—2.Reactor线程模型一
查看>>
Netty源码—4.客户端接入流程一
查看>>
Netty源码—4.客户端接入流程二
查看>>
Netty源码—5.Pipeline和Handler一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty相关
查看>>
Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
查看>>
Network Sniffer and Connection Analyzer
查看>>
NetworkX系列教程(11)-graph和其他数据格式转换
查看>>
Networkx读取军械调查-ITN综合传输网络?/读取GML文件
查看>>
Net与Flex入门
查看>>
net包之IPConn
查看>>
NFinal学习笔记 02—NFinalBuild
查看>>
NFS共享文件系统搭建
查看>>