Giter VIP home page Giter VIP logo

fishercoder1534 / leetcode Goto Github PK

View Code? Open in Web Editor NEW
3.7K 3.7K 1.3K 8.94 MB

Solutions to LeetCode problems; updated daily. Subscribe to my YouTube channel for more.

Home Page: https://youtube.com/FisherCoder

License: Apache License 2.0

Java 99.40% Shell 0.07% C++ 0.34% JavaScript 0.17% Python 0.01%
algorithm apache bash data-structures interview java leetcode leetcode-java leetcode-questions leetcode-solutions leetcoder mysql

leetcode's People

Contributors

anacoder1 avatar andrefpoliveira avatar anshul1507 avatar anushkagurjar99 avatar ashmichheda avatar coderaky avatar fishercoder1534 avatar gaurangi99 avatar gurungr2 avatar havanagrawal avatar ildar10 avatar javadev avatar jianminchen avatar ltp88 avatar praneshasp avatar shisheng-1 avatar sushant-sinha avatar teresachenec avatar varunu28 avatar west-dbest avatar willshen7789 avatar xdongyan avatar yaodehaung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leetcode's Issues

54. Spiral Matrix - LeetCode

Time complexity of this program is fine O(n*m), but space complexity can be O(1).
Here is my code,

import java.util.ArrayList;
import java.util.List;

class Solution 
{
    public List<Integer> spiralOrder(int[][] A) 
    {
        
        if ((A == null) || (A.length == 0) || (A[0].length == 0))
        {
            
            return (new ArrayList <Integer> ());
            
        }
        int lr = 0, ur = A.length, lc = 0, uc = A[0].length;
        List <Integer> arr = new ArrayList <Integer> ();
        int count = 0, t = 0, x = 0, y = 0;
        int offset [] = {0, 1};
        while (count < (A.length * A[0].length))
        {

            if (((y + offset[1]) == uc) || ((x + offset[0]) == ur) || ((y + offset[1]) < lc) || ((x + offset[0]) < lr))
            {

                if (((y + offset[1]) == uc))
                {

                    lr += 1;

                }
                else if (((x + offset[0]) == ur))
                {

                    uc -= 1;

                }
                else if (((y + offset[1]) < lc))
                {

                    ur -= 1;

                }
                else if (((x + offset[0]) < lr))
                {

                    lc += 1;

                }
                t = offset[0];
                offset[0] = offset[1];
                offset[1] = -t;

            }
            arr.add(A[x][y]);
            x += offset[0];
            y += offset[1];
            count += 1;

        }
        return (arr);
        
    }
}


Let me know what you think sir, ๐Ÿ˜‰ ๐Ÿ˜„ .
If you don't consider the array to be returned and just print the values as they are, space complexity will be O(1).

Wrong Table Header

I believe that you have switched places the "Tag" and the "Difficulty" header

_149 Max Points on a Line [Updated solution]

Input types were changed on April 15, 2019.
The solution in _149.java doesn't work anymore.
Below is the new solution: (credits)

class Solution {
    public int maxPoints(int[][] points) {
        if(points.length < 3)return points.length;
        int max = 0;
        HashMap<Long, Integer> map = new HashMap<Long, Integer>();
        for(int i = 0;i < points.length;i++) {
            int dup = 1;
            map.clear();
            for(int j = i + 1;j < points.length;j++) {
                int dx = points[j][0] - points[i][0], dy = points[j][1] - points[i][1];
                if(dx == 0 && dy == 0)dup++;
                else {
                    int gcd = getGcd(dx, dy);
                    long slope = ((long)(dy / gcd) << 32) + (dx / gcd);
                    map.put(slope, map.getOrDefault(slope, 0) + 1);
                }               
            }
            max = Math.max(max, dup);
            for(Map.Entry<Long, Integer> entry : map.entrySet())
                max = Math.max(max, entry.getValue() + dup);
        }
        return max;
    }
    
    int getGcd(int a, int b) {
        return b == 0 ? a : getGcd(b, a % b);
    }
}

#322 has the incorrect answer

It is the solution for #518 which is the same coin change question but requires a different answer for minimum required vs number of combinations. Comment also links to #518.

Solve problem 222 iteratively

Hi Jiahuan,

I looked at your code for problem 222, very nice!
To improve it, you may want to do it iteratively instead of using recursion.

Shuo

#401 Binary Watch has an incorrect solution

When you run it against the provided test case it even fails

Input
1

Output
["0:01","0:02","0:04","0:08","0:16","0:32","1:04","2:08","4:16","8:32"]
Expected
["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]

You can't treat hour like 60 minutes here, it's not a regular clock.

_49 test case seems to be incorrect

Hi,
the test case written for _49 does not check if anagrams are grouped together correctly. It only cares if all the elements given in input are a part of the actual ArrayList. Eg: if I have incorrect grouping as follows for expected , the test case will still pass:

{
  {"eat", "ate", "tea"},
  {"tan"},
  {"nat","bat"}
}

assertEquals(expected.containsAll(actual), actual.containsAll(expected));

Please let me know if I missed anything

Regards,
Prashant

In 724, why pivot index = 0 is a valid solution?

Hi,

Can you please share your thoughts on why pivot index = 0 is a right answer?
I can see that in your solution at this line, you have purposely coded this condition (the first condition of OR construct).

The case for which this happens is:

[ -1, -1, -1, 0, 1, 1]

Would request you to reply over this discussion thread and share your thoughts. Lot of people are having same doubt.

Thanks.

Boolean Perfect Number

Hi, I like your solutions. I thought of a different approach to the code for Perfect Number,

public boolean isPerfectNumber(int number){
         
        int temp = 0;
        for(int i=1;i<=number/2;i++){
            if(number%i == 0){
                temp += i;
            }
        }
        if(temp == number){
            System.out.println(""It is a perfect number"");
            return true;
        } else {
            System.out.println(""It is not a perfect number"");
            return false;
        }

Looks like mistake in the code #1836

Current implementation will return only one element in all cases.
Fix is to skip duplicates and stay only unique elements. Fix attached to this issue.
Screenshot 2023-12-12 at 12 14 57

709 problem statement

We are not allowed to use .toLowerCase() ๐Ÿ˜€ (even i did the same).....
You can close this issue without any changes ๐Ÿ˜‰

Another Solution for leetcode java 1217

class Solution {
public int minCostToMoveChips(int[] position) {
int even = 0;
int odd = 0;
for(int i : position) {
if(i % 2 == 0) even++;
else odd++;
}
return Math.min(even, odd);
}
}

This solution is much easier to understand. Actually i am learning and building my skills for open source so please assign me this issue to help me grow !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.