查看: 1729| 回复: 3
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] 【第四轮】4.13 - 4..19 Career Cup 3.1

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
3.1 Describe how you could use a single array to implement three stacks.


请参加活动的童鞋跟帖回复自己的解法,回复请参考以下格式:

    【解题思路】
    【时间复杂度】
    【空间复杂度】
    【gist link]
    【test case】(optional,如果觉得比较好,欢迎贴出来分享)

Notice:
1、记得在程序注释中表明自己算法的时间、空间复杂度
2、代码难懂之处加注释
3、每道题目有对应的帖子,除了贴解法,欢迎探讨各种follow up questions,集思广益
4、任何未尽之处,欢迎回报名帖提问,我会进一步作出修改



上一篇:LC新题,Binary Tree Up Side Down讨论
下一篇:【第四轮】4.13 - 4.19 Career Cup 3.2
🔗
laonong15 2015-4-16 04:08:23 | 只看该作者
全局:
【解题思路】
   
* Flexible division.
* the first stack start from   beginning of the  array and move forward like :
* Array  [0,1,2,3...]
* stack1 bottom -- > top
* empty when top =-1;
*
* the second stack start from  end of  the   array and  move backward  like
* Array  [..... n-2,n-2,n-1]
* stack2 :top <-- bottom
* empty  when top = n;
*
* The third  star from  in the middle of the array  could be  n/2 or n/3 and move forward, also
*  use two pointer to know the  start and the end of the  stack  Like
*
* Array  [n/2,n/2+1,n/2+2,...]
* stack3 : bottom(start)-->top(end)
* empty  end =start-1
*
* the functions  will be
*
* push(stackNum, data)
*
* pop (stackNum)
*
* isEmpty(stackNum)
*
* when push data to  one  stack   be careful to see if  it collide to the boundary of the other stack.

【时间复杂度】
    【空间复杂度】
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-FSBZA  2015-4-18 06:27:52
【解题思路】
将一个数组分成等分的三段,给每一段赋一个指针(所以栈的长度是固定的)
【时间复杂度】
push和pop操作都是O(1)
【空间复杂度】
O(n)
【gist link】
https://gist.github.com/alikewmk ... 3-1-arraystack-java
回复

使用道具 举报

🔗
Godbless 2015-6-2 12:12:08 | 只看该作者
全局:
  【解题思路】Divide the array into three equal parts, implement push, pop, peek
        and other basic stack functions to build stacks for each part.
    【时间复杂度】O(1) for both push and pop
    【空间复杂度】O(n)
    【gist link] https://github.com/StephenWeiXu/ ... aster/Chap3/3_1.cpp
    【test case】(optional,如果觉得比较好,欢迎贴出来分享)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表