@Shashank

You can enhance further by moving  border condition check for i & j before
you access them i.e,
(i>0 && j>0 ) & &( lm > a[i-1][j-1] ) ;

also location is to be saved not numbers. :)


On Thu, Aug 25, 2011 at 5:35 PM, WgpShashank <[email protected]>wrote:

> If i got the question correct then its Simple & Straightforward, We need to
> Check All neighbors, With Boundary conditions
>
> public static List<Integer> findLocalMaxima(Integer a[][])
> {
>
> List<Integer> locals = new ArrayList<Integer>();
>
> int row=a.length;
>
> for (int i = 0; i < row;i++)
> {
> int col=a[i].length;
> for (int j = 0; j < col; j++)
> {
> Integer lm=a[i][j];
> Boolean aa= ( lm > a[i-1][j-1] ) && (i>0 && j>0 );
> Boolean b=(lm > a[i][j-1]) && j>0;
> Boolean c= (lm > a[i-1][j]) && i>0;
> Boolean d= (lm > a[i][j+1]) && j<col-1;
> Boolean e= (lm > a[i-1][j+1]) && (i>0 && j<col-1);
> Boolean f= (lm > a[i+1][j-1]) && (i<row-1 && j>0);
> Boolean g= (lm > a[i+1][j]) && i<row-1;
> Boolean h= (lm > a[i+1][j+1]) && (i<row-1 && j<col-1);
>
> if( aa && b && c && d && e && f && g && h )
> locals.add(a[i][j]);
>
> }
> }
>
> return locals;
> }
>
> correct me if anything wrong ?
>
> *Thanks
> Shashank Mani
> Computer Science
> Birla Institute of Technology Mesra*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/5xmX_nyPRKkJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to