7 changes: 6 additions & 1 deletion 7 leetcode-x/find-majority-element/README.md Original file line numberDiff line numberDiff line change @@ -26,4 +26,9 @@ find majority element(主要元素) 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/find-majority-element-lcci 著作权归...
leetcode majority elements Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times. You may assume that the array is non-empty and the majority element always exist in the array. 解法: As we sweep we maintain a pa...
A peak element is an element that is greater than its neighbors. Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index. The array may contain multiple peaks, in that case return the index to any one of the peaks is fine. You may imagine thatnum[...
.gitignore .prettierrc .problemList.json .problemSiteData.json .rufo 169-Majority Element.cpp 554-Brick-Wall.py CONTRIBUTING.md LICENSE README.md README_template.md updateSiteData.js verifySiteData.jsBreadcrumbs leetcode-solutions /python / 0724-find-pivot-index.py Latest...
给出左右两个字符串,如果左边的字符串(ransom note)能够用右边(magazines )的字符串构造出来,则返回true,否则返回false。注意,magazines 中的字符串每个只能用一次。 思路: 参考了Leetcode Discuss里的大神答案:用一个整型数组arr记录magazines 里每个字符出现的次数。然后遍历ransom note字符串,修改arr中的值使每个字...
很明显,通过每次nums[num]的赋值,数值最后会进入一个循环,说明只要这个数组里存在重复项,那么按照刚刚的赋值方法必定会进入循环。而且我们发现首次进入循环时的数字就是我们的重复项。因此我们可以通过建立快慢指针,找到循环数组的入口点,这个入口点的数值就是本题需要求解的重复项!
Find Peak Element publicclassSolution {publicintfindPeakElement(int[] num) {//binary searchhttp://siddontang.gitbooks.io/leetcode-solution/content/array/find_peak_element.htmlif(num==null|| num.length ==0)return-1;if(num.length==1)return0;intleft=0, right=num.length-1;intmid=left+(...
Demonstrate all the questions on LeetCode in the form of animation.(用动画的形式呈现解LeetCode题目的思路) - fanfind/LeetCodeAnimation
Leetcode之二分法专题-287. 寻找重复数(Find the Duplicate Number) 给定一个包含n+ 1 个整数的数组nums,其数字都在 1 到n之间(包括 1 和n),可知至少存在一个重复的整数。假设只有一个重复的整数,找出这个重复的数。 示例1: 输入:[1,3,4,2,2]输出: 2 ...
0169-majority-element.rs 0179-largest-number.rs 0190-reverse-bits.rs 0191-number-of-1-bits.rs 0198-house-robber.rs 0199-binary-tree-right-side-view.rs 0200-number-of-islands.rs 0202-happy-number.rs 0205-isomorphic-strings.rs 0206-reverse-linked-list.rs 0207-course-schedule.rs 0208-implement...