分析:就是建立一个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. input type="number"时,maxlength不起作用怎么解决

    最近小颖在做公司的angular项目时,发现当input type="number"时,maxlength不起作用,百度了下解决方式,顺便记录下,以便后期查看嘻嘻 <inpu ...

  2. JDK1.8版本,java并发框架支持锁包括

    1.自旋锁,自旋,jvm默认是10次,由jvm自己控制,for去争取锁 2.阻塞锁 被阻塞的线程,不会争夺锁 3.可重入锁,多次进入改锁的域 4.读写锁 5.互斥锁,锁本身就是互斥的 6.悲观锁,不相 ...

  3. 【转载】51单片机data,bdata,idata,xdata使用注意事项

    "51单片机编程在不同内存空间data xdata bdata定义变量的注意事项": 关键词:51 单片机 编程 不同 内存空间 data xdatabdata 定义 变量 注意事 ...

  4. 解决 Python shell 中 Delete/Backspace 键乱码问题

    简述 进入 Python shell,按下 Delete/Backspace 键,会出现 ^H 字符.命令输入错误后只能从头开始,无法删除,让人很头疼.为了便于后期使用,分享一个一劳永逸的方式. 基本 ...

  5. vue之介绍

    vue的作者叫尤雨溪,中国人.自认为很牛逼的人物,也是我的崇拜之神. 关于他本人的认知,希望大家读一下这篇关于他的文章,或许你会对语言,技术,产生浓厚的兴趣.https://mp.weixin.qq. ...

  6. powerdesigner唯一约束设置

    双击unique_pos_code

  7. MANIFEST.MF的用途

    可以用的上的有: 1. Main-Class 指定程序的入口,这样可以直接用java -jar xxx.jar来运行程序. 2. Class-Path 指定jar包的依赖关系,class loader ...

  8. 在排序模型方面,点评搜索也经历了业界比较普遍的迭代过程:从早期的线性模型LR,到引入自动二阶交叉特征的FM和FFM,到非线性树模型GBDT和GBDT+LR,到最近全面迁移至大规模深度学习排序模型。

    https://mp.weixin.qq.com/s/wjgoH6-eJQDL1KUQD3aQUQ 大众点评搜索基于知识图谱的深度学习排序实践 原创: 非易 祝升 仲远 美团技术团队 前天    

  9. xcode工程编译错误:No architectures to compile for

    问题 开发环境:xcode6,iPhone6模拟器 xcode工程编译错误:No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active ...

  10. centos7设置iptables

    https://www.linuxidc.com/Linux/2017-10/147238.htm