ARTS打卡第12周

A:Circular Array Loop  Medium

题目:

You are given a circular array nums of positive and negative integers.

If a number k at an index is positive, then move forward k steps. Conversely,

if it's negative (-k), move backward k steps. Since the array is circular,

you may assume that the last element's next element is the first element,

and the first element's previous element is the last element.

Determine if there is a loop (or a cycle) in nums. A cycle must start and end at the same index and the cycle's length > 1.

Furthermore, movements in a cycle must all follow a single direction. In other words, a cycle must not consist of both forward and backward movements.

题意:给定一个存在正数和负数的数组,寻找数组中的是否存在循环,假设数组首位相连,当第i位数是正数时向前行进nums[i]位,当第i位数是负数时向后行进|nums[i]|位,

一个循环必须拥有两个及以上的元素组成,并且循环的移动方向要一致

思路:使用一个boolean类型的数组记录移动方向一致,最终失败的元素,当遇到这类元素的时候直接终止本次的尝试,使用一个boolean类型的数组记录本次尝试移动方向一致的元素,

当移动方向一致,下一元素j是已经出现过的并且和当前元素不同,得出存在循环,如果方向一致,下一元素j是未记录的元素,则以j为当前元素,继续查找下一元素,

遇到方向不一致是终止当前尝试,更换起始的元素。

方案:https://leetcode.com/submissions/detail/234708275/     

https://leetcode.com/submissions/detail/234707586/  

R:本周学习了http://open.163.com/movie/2010/12/3/A/M6UTT5U0I_M6V2TGI3A.html 全域哈希和完全哈希,全域哈希是使用随机算法从一个哈希函数集合中选取一个哈希函数,

避免由于被恶意的针对,对于任意的不相等key的x和y, 当槽的数量为m时,从哈希函数集中选择一个哈希函数,这两个key,发生冲突的概率是1/m。

完全哈希的思想就是采用两级的框架,每一级上都用全域哈希。完全哈希可以在最坏情况下以O(1)复杂度查找,性能出色。

T:本周查看了java的HashMap的实现,和算法导论中提到的普通哈希一致,都是将不同的key经过hash算法,映射到不同的槽里,当遇到不同的key的hash值一致的时候,

根据不同的情况将对应的key写入到链表中或者二叉树中。在查找相同的hash值的key时,遍历链表或者二叉树进行查找,删除和查找的方式一致。

S:http://open.163.com/movie/2018/8/Q/R/MDPBV80UO_MDPBVMKQR.html,分享一个关于无聊如何能够带来你最出色的想法的演讲,讲如何降低手机的使用频率,

利用空闲的时间做更多有意义的事情,而不是被手机支配,要把手机当做工具,分享里面的一句话,把客户叫“用户”的人,除了毒贩就是科技人员了。

posted @ 2019-06-09 23:13  wujunjie007  阅读(106)  评论(0编辑  收藏  举报