哈嘍,大家好!由於公眾號做了改版,為了保證公眾號的文章可以準時推送到你手裡,大家記得點擊上方藍色」菜鳥名企夢「,將咱們的公眾號 加星標置頂 ,在此真誠的表示感謝~
LeetCode Top 100高頻算法題,即LeetCode上最高頻的100道求職面試算法題。小編和實驗室同學之前面試找工作,也只刷了劍指offer和這top 100算法題,在實際面試中也遇到了很多LeetCode上的原題。劍指offer算法最優解之前和大家分享了,LeetCode Top 100這100道算法題,每道題小編都刷了很多遍,並且總結了一種最適合面試時手撕算法的最優解法。後續每天和大家分享一道LeetCode top 100高頻算法題,以及小編總結的最優解法。
如果本專欄對你有幫助,幫忙點個讚~
如果沒什麼人看,後續可能不更新這專欄了,意義不大
LeetCode Top 100 高頻算法題系列的LeetCode算法題目就不幫大家翻譯了,程式設計師應該需要能看懂。LeetCode算法題有一個技巧:先看每道題的example,大部分情況看完example就能理解題目意思;如果看完example還有疑惑,可以再回過頭來看英文題目,這樣也可以節省一點時間~
Given an array of non-negative integers nums, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.You can assume that you can always reach the last index.Input: nums = [2,3,1,1,4]
Output: 2
Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
Input: nums = [2,3,0,1,4]
Output: 2
3. Constraints(輸入的數據約束)
在LeetCode上本題屬於Hard難度,難點在於O(n)的複雜度。本題的解法需要仔細琢磨下, 直接貼代碼,代碼中加了詳細的注釋
class Solution { public int jump(int[] nums) { int sc = 0; int max = 0; int e = 0; for(int i=0;i<nums.length-1;i++){ max = Math.max(max,i+nums[i]); if(i==e){ sc++; e = max; } } return sc; }}
最後:由於公眾號做了改版,為了保證公眾號的文章可以準時推送到你手裡,大家記得將咱們的公眾號 加星標置頂 ,在此真誠的表示感謝~
長按,掃碼,關注
及時收看更多精彩內容
點擊」閱讀原文「:領取5T精品資料,面試總結、100+實戰項目
我知道你 「在看」