分析:就是建立一个boolean array来记录array里面每个元素的访问情况,遇到访问过的元素就停止visiting,返回未访问的结点个数

 public int visiting(int[] A, int N) {
if (A==null || A.length==0) return 0;
int cur = 0;
int count = 0;
boolean[] visited = new boolean[N];
while (cur>=0 && cur<A.length && !visited[cur]) {
visited[cur] = true;
cur = cur + A[cur];
count++;
}
return N-count;
}

Twitter OA prepare: Visit element of the array的更多相关文章

  1. Twitter OA prepare: Equilibrium index of an array

    Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to ...

  2. Twitter OA prepare: Two Operations

    准备T家OA,网上看的面经 最直接的方法,从target降到1,如果是奇数就减一,偶数就除2 public static void main(String[] args) { int a = shor ...

  3. Twitter OA prepare: Flipping a bit

    You are given a binary array with N elements: d[0], d[1], ... d[N - 1]. You can perform AT MOST one ...

  4. Twitter OA prepare: even sum pairs

    思路:无非就是扫描一遍记录奇数和偶数各自的个数,比如为M和N,然后就是奇数里面选两个.偶数里面选两个,答案就是M(M-1)/2 + N(N-1)/2

  5. Twitter OA prepare: K-complementary pair

    2sum的夹逼算法,需要sort一下.本身不难,但是tricky的地方在于允许同一个数组元素自己跟自己组成一个pair,比如上例中的[5, 5].而且数组本身就允许值相等的元素存在,在计算pair时, ...

  6. Twitter OA prepare: Anagram is A Palindrome

    Algorithm: Count the number of occurrence of each character. Only one character with odd occurrence ...

  7. Twitter OA prepare: Rational Sum

    In mathematics, a rational number is any number that can be expressed in the form of a fraction p/q ...

  8. check the element in the array occurs more than half of the array length

    Learn this from stackflow. public class test { public static void main(String[] args) throws IOExcep ...

  9. Kth Largest Element in an Array

    Find K-th largest element in an array. Notice You can swap elements in the array Example In array [9 ...

随机推荐

  1. Coding和Git的环境搭建

    Github太慢了.打开网页慢,下载也只有几kb. 于是找了国内的Git,据说coding不错.就申请了个. 其实csdn也有...但是没人家的专业... 1 注册coding  https://co ...

  2. VS2013打开2008的项目

    找到 .csproj 后缀的文件.然后右键选择文本打开. 找到下面一段话: <ProjectTypeGuids>-00065b846f21};{fae04ec0-301f-11d3-bf4 ...

  3. JavaScript通知浏览器,更改通知数目

    http://lab.ejci.net/favico.js/ http://www.zhangxinxu.com/study/201607/web-notifications.html http:// ...

  4. CentOS上传下载查看命令

    之前往CentOS中上传都用ftp软件,这里介绍一种另外的上传下载方式,两个命令轻松搞定.这两个命令目前只针对Xshell和SecureCRT等远程终端软件才支持,并且还会有时间的限制.大概30秒不上 ...

  5. Java秒杀简单设计二:数据库表和Dao层设计

    Java秒杀简单设计二:数据库表Dao层设计 上一篇中搭建springboot项目环境和设计数据库表  https://www.cnblogs.com/taiguyiba/p/9791431.html ...

  6. springmvc如何访问到静态的文件,如jpg,js,css

    如何你的DispatcherServlet拦截"*.do"这样的有后缀的URL,就不存在访问不到静态资源的问题. 如果你的DispatcherServlet拦截"/&qu ...

  7. 三个Linux权限

    Linux有三种不同类型的用户可对文件或目录进行访问,分别是:文件所有者,同组用户.其他用户. 每一文件或目录的访问权限都有三组,每组用三位表示,分别为:1)文件属主的读.写和执行权限:2)和属主同组 ...

  8. 9.8Django书单列表3.0

    2018-9-8 19:03:17 我暂且叫书单商城吧  更加优化了一下 这个网站有好多的样式前端的福利  https://v3.bootcss.com/ 3.0版本  放在了github  :htt ...

  9. 8.30前端jQuery和数据结构知识

    2018-8-30 16:37:17 单链表的demo 从俺弟家回来了! 发现,还是要努力学习是很重要的!!努力学习新的感兴趣的东西!! 多读书还是很重要的!!! 越努力,越幸运! # coding: ...

  10. scala - fold,aggregate,iterator

    import org.json4s._ import org.json4s.jackson._ import org.json4s.jackson.JsonMethods._ import org.j ...