Why my O(n) Java solution is accepted.

  • 0

    I'm happy that my O(n) solution is accepted. I know a better solution is using binary search.

    Here is my code in Java. Its' quite clean and clear. I'm just wondering what's the rule of OJ's judgement system.

    public class Solution {
    public int findMin(int[] num) {

        int result = num[0];
        for(int i = 1; i < num.length; i++)
            if( num[i] < num[i-1])
                result = num[i];
        return result;
        // the above linear time solution is acceptable.
        // a better solution is using binary search.


  • 0

    I use the same method as you and this is my first code program on this website

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.