当前位置: 首页 > news >正文

网站内容好网站开发猪八戒

网站内容好,网站开发猪八戒,代码编辑器,上海营销活动策划公司★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号#xff1a;山青咏芝#xff08;shanqingyongzhi#xff09;➤博客园地址#xff1a;山青咏芝#xff08;https://www.cnblogs.com/strengthen/#xff09;➤GitHub地址山青咏芝shanqingyongzhi➤博客园地址山青咏芝https://www.cnblogs.com/strengthen/➤GitHub地址https://github.com/strengthen/LeetCode➤原文地址https://www.cnblogs.com/strengthen/p/11297779.html ➤如果链接不是山青咏芝的博客园地址则可能是爬取作者的文章。➤原文已修改更新强烈建议点击原文地址阅读支持作者支持原创★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ Implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializes an array-like data structure with the given length.  Initially, each element equals 0.void set(index, val) sets the element at the given index to be equal to val.int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1.int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_idExample 1: Input: [SnapshotArray,set,snap,set,get] [[3],[0,5],[],[0,6],[0,0]] Output: [null,null,0,null,5] Explanation: SnapshotArray snapshotArr new SnapshotArray(3); // set the length to be 3 snapshotArr.set(0,5); // Set array[0] 5 snapshotArr.snap(); // Take a snapshot, return snap_id 0 snapshotArr.set(0,6); snapshotArr.get(0,0); // Get the value of array[0] with snap_id 0, return 5 Constraints: 1 length  50000At most 50000 calls will be made to set, snap, and get.0 index  length0  snap_id  (the total number of times we call snap())0  val 10^9实现支持下列接口的「快照数组」- SnapshotArray SnapshotArray(int length) - 初始化一个与指定长度相等的 类数组 的数据结构。初始时每个元素都等于 0。void set(index, val) - 会将指定索引 index 处的元素设置为 val。int snap() - 获取该数组的快照并返回快照的编号 snap_id快照号是调用 snap() 的总次数减去 1。int get(index, snap_id) - 根据指定的 snap_id 选择快照并返回该快照指定索引 index 的值。示例 输入[SnapshotArray,set,snap,set,get][[3],[0,5],[],[0,6],[0,0]] 输出[null,null,0,null,5] 解释 SnapshotArray snapshotArr new SnapshotArray(3); // 初始化一个长度为 3 的快照数组 snapshotArr.set(0,5); // 令 array[0] 5 snapshotArr.snap(); // 获取快照返回 snap_id 0 snapshotArr.set(0,6); snapshotArr.get(0,0); // 获取 snap_id 0 的快照中 array[0] 的值返回 5 提示 1 length  50000题目最多进行50000 次setsnap和 get的调用 。0 index  length0  snap_id  我们调用 snap() 的总次数0  val 10^9480ms 1 class SnapshotArray {2 3 private var dict [Int: Int]()4 private var snapshots [[Int: Int]]()5 6 init(_ length: Int) {7 //array Array(repeating: 0, count: length 1)8 }9 10 func set(_ index: Int, _ val: Int) { 11 dict[index] val 12 } 13 14 func snap() - Int { 15 snapshots.append(dict) 16 return snapshots.count - 1 17 } 18 19 func get(_ index: Int, _ snap_id: Int) - Int { 20 return snapshots[snap_id][index] ?? 0 21 } 22 } 23 24 /** 25 * Your SnapshotArray object will be instantiated and called as such: 26 * let obj SnapshotArray(length) 27 * obj.set(index, val) 28 * let ret_2: Int obj.snap() 29 * let ret_3: Int obj.get(index, snap_id) 30 */ Runtime: 828 ms Memory Usage: 27.8 MB 1 class SnapshotArray {2 var vv:[[Int:Int]] [[Int:Int]]()3 4 init(_ length: Int) {5 vv.append([Int:Int]()) 6 }7 8 func set(_ index: Int, _ val: Int) {9 vv[vv.count - 1][index] val 10 } 11 12 func snap() - Int { 13 vv.append([Int:Int]()) 14 return vv.count - 2 15 } 16 17 func get(_ index: Int, _ snap_id: Int) - Int { 18 for i in stride(from:snap_id,through:0,by:-1) 19 { 20 if vv[i][index] ! nil 21 { 22 return vv[i][index]! 23 } 24 } 25 return 0 26 } 27 } 28 29 /** 30 * Your SnapshotArray object will be instantiated and called as such: 31 * let obj SnapshotArray(length) 32 * obj.set(index, val) 33 * let ret_2: Int obj.snap() 34 * let ret_3: Int obj.get(index, snap_id) 35 */   转载于:https://www.cnblogs.com/strengthen/p/11297779.html
http://www.yutouwan.com/news/141801/

相关文章:

  • 做网站的语言叫什么谷歌网站流量统计
  • 扁平化资讯网站模板长春seo外包
  • 新手站长做什么网站建筑设计专业推荐网站
  • 网站的 规划与建设开发网站那个好
  • 火烈鸟门户网站开发wordpress查询
  • 药类网站整站模板下载无锡企业推广网站
  • 网站怎么盈利驻马店河南网站建设
  • wordpress 后台实现轮播图企业商务网站优化
  • 展示网站欣赏千锋教育培训机构地址
  • 手机网站的特点北京seo相关
  • 连云港外贸网站建设公众号开发者密钥重置影响
  • 怎么建网站手机版正在直播足球比赛
  • 兰州网站网站建设一个网站需要哪些技术
  • 电脑怎么建网站wordpress二维码 插件下载
  • 个人网站名称请广州安全教育平台作业
  • 怎么进入网站管理系统天津谷歌优化公司
  • 网站建设之婚礼摄影网站设计网站建设设计培训班
  • 网站开发安全模块方案jquery购物网站
  • 公司网站上传ftp教程福州全网网站建设
  • 手机上搭建个人网站网站建设的人才怎么称呼
  • 做网站找哪家公司网站多语言包
  • 怀化百度整站优化服务怎么做网站后端
  • 网站开发属于程序员吗php 建设网站
  • 如何更换网站域名吉林省建设厅官网查询
  • 建设做网站微信小程序制作公司
  • 江岸网站建设...无锡网站制作
  • 深圳做个网站要多少钱微信官方网站网址
  • 稻香村网站建设迅当网络外贸网站建设980
  • html5 素材网站网站和数字界面设计师
  • 提高网站排名的软件广安门内网站建设