closest

python leetcode 16. 3Sum Closest

匿名 (未验证) 提交于 2019-12-02 22:11:45
方法与 3Sum 类似 class Solution ( object ) : def threeSumClosest ( self , nums , target ) : """ :type nums: List[int] :type target: int :rtype: int """ nums . sort ( ) mindiff = 1000000 ln = len ( nums ) res = sum ( nums [ : 3 ] ) for i in range ( ln - 2 ) : left , right = i + 1 , ln - 1 while left < right : sum1 = nums [ i ] + nums [ left ] + nums [ right ] diff = abs ( sum1 - target ) if diff == 0 : return target if diff < mindiff : mindiff = diff res = sum1 if sum1 > target : right -= 1 if sum1 < target : left += 1 return res 转载请标明出处: python leetcode 16. 3Sum Closest 文章来源: python leetcode 16.

Angular - Focus on input with dynamic IDs on click

你。 提交于 2019-12-02 20:19:34
问题 *There are a lot of similar questions but I have not found a true duplicate that answers my question Apologies if I missed something. I have a page with several inputs/buttons (The same component repeated) and need to focus on the correct input upon button click. I have tried variations of elementRef, nativeElement, focusing based on the ID... but I can only get it to focus on the first one in the DOM or specific ones... <ng-template #myTemplate let-context="context"> <input #foo [id]="

Angular - Focus on input with dynamic IDs on click

时光毁灭记忆、已成空白 提交于 2019-12-02 12:25:55
*There are a lot of similar questions but I have not found a true duplicate that answers my question Apologies if I missed something. I have a page with several inputs/buttons (The same component repeated) and need to focus on the correct input upon button click. I have tried variations of elementRef, nativeElement, focusing based on the ID... but I can only get it to focus on the first one in the DOM or specific ones... <ng-template #myTemplate let-context="context"> <input #foo [id]="'myInput'+context.id" /> <button class="btn" [id]="'btnAction'+context.id (click)="focusOnInput()"></button>

How to find the nearest points to given coordinates with MATLAB?

孤街醉人 提交于 2019-12-01 22:26:07
问题 I need to solve a minimization problem with Matlab and I'm wondering which is the easiest solution. All the potential solutions that I've been thinking in require lot of programming effort. Suppose that I have a lat/long coordinate point (A,B), what I need is to search for the nearest point to this one in a map of lat/lon coordinates. In particular, the latitude and longitude arrays are two matrices of 2030x1354 elements (1km distance) and the idea is to find the unique indexes in those

JQuery: Closest div that has an ID

为君一笑 提交于 2019-12-01 15:00:03
How would you write the Jquery to get the closest div that actually has an ID defined? gor You should use has attribute selector . This sample should do the work: $('selector').closest('[id]') $(elementToStart).parent().closest('div[id]'); I use the parent() to avoid just getting the element itself. Example: http://jsfiddle.net/zQRFT/1/ Look for an id attribute on a div, using the closest method : $(this).closest('div[id]'); The [id] brackets there is what's called the Has Attribute Selector 来源: https://stackoverflow.com/questions/5096103/jquery-closest-div-that-has-an-id

JQuery: Closest div that has an ID

淺唱寂寞╮ 提交于 2019-12-01 13:47:14
问题 How would you write the Jquery to get the closest div that actually has an ID defined? 回答1: You should use has attribute selector. This sample should do the work: $('selector').closest('[id]') 回答2: $(elementToStart).parent().closest('div[id]'); I use the parent() to avoid just getting the element itself. Example: http://jsfiddle.net/zQRFT/1/ 回答3: Look for an id attribute on a div, using the closest method: $(this).closest('div[id]'); The [id] brackets there is what's called the Has Attribute

R - Assign column value based on closest match in second data frame

你。 提交于 2019-11-30 20:54:44
I have two data frames, logger and df (times are numeric): logger <- data.frame( time = c(1280248354:1280248413), temp = runif(60,min=18,max=24.5) ) df <- data.frame( obs = c(1:10), time = runif(10,min=1280248354,max=1280248413), temp = NA ) I would like to search logger$time for the closest match to each row in df$time, and assign the associated logger$temp to df$temp. So far, I have been successful using the following loop: for (i in 1:length(df$time)){ closestto<-which.min(abs((logger$time) - (df$time[i]))) df$temp[i]<-logger$temp[closestto] } However, I now have large data frames (logger

jQuery find closest parent link with attribute

本秂侑毒 提交于 2019-11-30 20:41:34
I'd like to find the closest link with attribute findme from a children .startpoint . Structure: <ul> <li><a href="#">Point one</a></li> <li><a href="#" data-findme="yipi">Point one</a> <ul> <li><a href="#">Hello</a></li> <li><a href="#">Hello</a> <ul> <li><a href="#" class="startpoint">My Startpoint</a></li> </ul> </li> </ul> </li> </ul> JavaScript (jQuery): $(document).ready(function(){ console.log( $('.startpoint').closest("*[data-findme]") ); }); Since the problem is, that the element data-findme is not a a parent element instead it is another child of a parent, my example will not find

Finding closest pair of points on a sphere

六眼飞鱼酱① 提交于 2019-11-30 14:19:28
I know how to implement n log n closest pair of points algorithm (Shamos and Hoey) for 2D cases (x and y). However for a problem where latitude and longitude are given this approach cannot be used. The distance between two points is calculated using the haversine formula. I would like to know if there is some way to convert these latitudes and longitudes to their respective x and y coordinates and find the closest pair of points, or if there is another technique that can be used to do it. I would translate them to three dimensional coordinates and then use the divide and conquer approach using

jQuery find closest parent link with attribute

淺唱寂寞╮ 提交于 2019-11-30 04:43:45
问题 I'd like to find the closest link with attribute findme from a children .startpoint . Structure: <ul> <li><a href="#">Point one</a></li> <li><a href="#" data-findme="yipi">Point one</a> <ul> <li><a href="#">Hello</a></li> <li><a href="#">Hello</a> <ul> <li><a href="#" class="startpoint">My Startpoint</a></li> </ul> </li> </ul> </li> </ul> JavaScript (jQuery): $(document).ready(function(){ console.log( $('.startpoint').closest("*[data-findme]") ); }); Since the problem is, that the element