# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 45: Jump Game IIhttps://oj.leetcode.com/problems/jump-game-ii/ Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the arra…
题目要求:Jump Game II Given an array of non-negative integers, 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 minim…
Given an array of non-negative integers, 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…
题目: Given an array of non-negative integers, 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 j…
给定一个非负整数数组,你最初位于数组的首位.数组中的每个元素表示你在该位置的最大跳跃长度.你的目标是用最小跳跃次数到达最后一个索引.例如: 给定一个数组 A = [2,3,1,1,4]跳到最后一个索引的最小跳跃数是 2.(从索引 0 跳到 1 跳1步,然后跳3步到最后一个索引.)注意:假设你总是可以到达最后一个索引位置.详见:https://leetcode.com/problems/jump-game-ii/description/ Java实现: curReach是维护的当前能跳到的最大位置…
题目 Given an array of non-negative integers, 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 ju…
[ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30] ] 观察,从左到右递增,从上到下递增.似乎找不到什么其他规律.第一想法是二分,笨方法. 感觉这个是有序数组求两个数的和为sum的扩展.巧妙啊!看了题解才会的. 观察左下角或者右下角的元素.所有比18大的,都在18右边.比18小的都在它上边. 只能感叹啊!什么时候能有这样的功力呢? bool se…
1.题目描述 2.题目分析 题目要求返回杨辉三角的某一行,需要将杨辉三角的某行的全部计算出来. 3.代码实现 vector<int> getRow(int rowIndex) { ) ,); vector<,}; ; while(n <= rowIndex){ vector<int> r = calNextline(b); b.resize( r.size() ); ; i < r.size(); i++){ b[i] = r[i]; } n++; } retur…
1.题目描述 2.问题分析 使用快慢指针方法判断链表是否有环,然后寻找环开始的节点. 3.代码 ListNode *detectCycle(ListNode *head) { if( head == NULL || head->next == NULL ){ return NULL ; } ListNode* fast = head; ListNode* slow = head; while( fast != NULL && slow != NULL ){ if( fast->…
1.题目描述 2.分析 首先将链表翻转,然后做加法. 最后将结果链表翻转. 3.代码 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode* L1 = reverseList( l1 ); ListNode* L2 = reverseList( l2 ); ListNode* head = ); ListNode* result = head; ListNode* p1 = L1; ListNode* p2 = L2; ;…