mountain

852. Peak Index in a Mountain Array

我怕爱的太早我们不能终老 提交于 2020-01-25 21:56:08
852. 山脉数组的峰顶索引 我们把符合下列属性的数组 A 称作山脉: A.length >= 3 存在 0 < i < A.length - 1 使得 A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] 给定一个确定为山脉的数组,返回任何满足 A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] 的 i 的值。 示例 1: 输入:[0,1,0] 输出:1 示例 2: 输入:[0,2,1,0] 输出:1 提示: 3 <= A.length <= 10000 0 <= A[i] <= 10^6 A 是如上定义的山脉 解法一 //时产复杂度O(n), 空间复杂度O(1) class Solution { public: int peakIndexInMountainArray(vector<int>& A) { int n = A.size(), i; for(i = 1; i < n; i++) { if(A[i - 1] < A[i]) continue; break; } return i - 1; } }; 解法二 //时间复杂度O(logn), 空间复杂度O(1) class Solution { public: int

LeetCode 845. Longest Mountain in Array

十年热恋 提交于 2020-01-04 15:00:28
原题链接在这里: https://leetcode.com/problems/longest-mountain-in-array/ 题目: Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: B.length >= 3 There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1] (Note that B could be any subarray of A, including the entire array A.) Given an array A of integers, return the length of the longest mountain . Return 0 if there is no mountain. Example 1: Input: [2,1,4,7,3,2,5] Output: 5 Explanation: The largest mountain is [1,4,7,3,2] which has length 5. Example 2: Input:

Can't run Composer on my Mac Mountain Lion - openssl extension

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I installed several CMS that require Composer. Since 2 days i got error and can't go on. [ RuntimeException ] You must enable the openssl extension to download files via https I check the following: $ openssl version OpenSSL 1.0 . 1e 11 Feb 2013 $ which openssl / opt / local / bin / openssl phpinfo say Phar - Native OpenSSL support enabled and OpenSSL support enabled. Still if i do $ php - info | grep openssl OpenSSL support => disabled ( install ext / openssl ) Does someone has a clue about what i should do to be able to run

OS X Mountain Lion: gcc-4.2 No such file or directory

匿名 (未验证) 提交于 2019-12-03 00:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Tried to install a gem on Mountain Lion and make couldn't find gcc-4.2: kamil$ gem install posix-spawn -v '0.3.6' Building native extensions. This could take a while... ERROR: Error installing posix-spawn: ERROR: Failed to build gem native extension. /Users/kamil/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb creating Makefile make compiling posix-spawn.c make: gcc-4.2: No such file or directory make: *** [posix-spawn.o] Error 1 回答1: If you have Xcode installed, gcc should be available. Check where it is with: kamil$ which gcc /usr/bin/gcc

LeetCode 845. Longest Mountain in Array

你说的曾经没有我的故事 提交于 2019-11-27 11:51:09
原题链接在这里: https://leetcode.com/problems/longest-mountain-in-array/ 题目: Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: B.length >= 3 There exists some 0 < i < B.length - 1 such that B[0] < B[1] < ... B[i-1] < B[i] > B[i+1] > ... > B[B.length - 1] (Note that B could be any subarray of A, including the entire array A.) Given an array A of integers, return the length of the longest mountain . Return 0 if there is no mountain. Example 1: Input: [2,1,4,7,3,2,5] Output: 5 Explanation: The largest mountain is [1,4,7,3,2] which has length 5. Example 2: Input:

模拟多人爬山

半世苍凉 提交于 2019-11-26 12:11:01
1 package com.twod4z; 2 /** 3 * @program: com.twod4z 4 * @description:爬山对象 线程 5 * @author: Mr.Lin 6 * @create: 2019年8月7日 7 **/ 8 public class Climb extends Thread{ 9 int time; //速度/米 10 int num; //每次休息时间 11 int mountain; //山的高度 12 13 public Climb(int time,int mountain) { 14 super(); 15 this.time=time; 16 this.mountain = mountain*1000; //千米 17 } 18 //run方法 19 public void run() { 20 String name=Thread.currentThread().getName(); //获取当前线程名 21 while(true) { 22 mountain-=100; //爬山 23 System.out.println(name+"爬了"+(num+1)+"个100米"); 24 num++; //爬100米次数+1 25 try { 26 Thread.sleep(time); //爬100米用的时间 27 }