Skip to content

Add Java solutions to existing problems #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mbucko opened this issue Feb 22, 2024 · 13 comments
Open

Add Java solutions to existing problems #5

mbucko opened this issue Feb 22, 2024 · 13 comments
Labels
enhancement New feature or request

Comments

@mbucko
Copy link
Owner

mbucko commented Feb 22, 2024

No description provided.

@mbucko mbucko added the enhancement New feature or request label Feb 22, 2024
@ThomasChen0717
Copy link
Contributor

Hi, I am looking to contribute to this project and I tried to run your program locally on my computer. I was able to build the project but afterwards, when I try to run the test for TwoSum, I am getting this error:
The bin directory /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/bin does not exist. Check the problem_builds_dir and problem arguments.
I noticed that there aren't a bin folder created after the build. I wonder how I can resolve that? Is it my misunderstanding?

@mbucko
Copy link
Owner Author

mbucko commented Feb 24, 2024

run it with -v option and it should print out all the folders that it's using. Also, can you tell me with what args you're running it?

@ThomasChen0717
Copy link
Contributor

Im running the default args as specified in README. Running -v tells me that the bin folder is missing. Am I supposed to build the project in the folder that I cloned the source code?

@mbucko
Copy link
Owner Author

mbucko commented Feb 24, 2024

Are you running it on windows?
Can you paste the entire output including the build and running the app it "-v" option?

@mbucko
Copy link
Owner Author

mbucko commented Feb 24, 2024

When you call ./problem_builds/openleetcode --problem_builds_dir ./problem_builds --language cpp --problem TwoSum it runs cmake and build inside problem_builds/problems/TwoSum/cpp which is when the bin folder is created with the executable for the tests.

If you specify -v option to openleetcode you might have more info about the failure. My guess is that it's failing to build because you're missing some dependency like the compiler....

@ThomasChen0717
Copy link
Contributor

I am running it on macOs. This is my terminal output:
styleys@ThomasdeMacBook-Pro openleetcode % cmake -B build -DCMAKE_BUILD_TYPE=Debug -DPROBLEM_BUILDS_NAME=problem_builds
-- Setting PROJECT_BUILDS_DIR to /Users/styleys/documents/Portfolio/openleetcode/problem_builds
-- The C compiler identification is AppleClang 14.0.3.14030022
-- The CXX compiler identification is AppleClang 14.0.3.14030022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.9s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/styleys/documents/Portfolio/openleetcode/build
styleys@ThomasdeMacBook-Pro openleetcode % cmake --build build
styleys@ThomasdeMacBook-Pro openleetcode % cmake --install build --config Debug
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/description.md
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/cpp/solution.cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/cpp/solution.md
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase1.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase2.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase3.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase4.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/NumberOfIslands/testcases/TestCase5.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/description.md
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solution.cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solution.md
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase6.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase13.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase12.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase7.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase15.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase14.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase1.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase2.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase3.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase11.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase4.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase8.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase9.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase5.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/testcases/TestCase10.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/description.md
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/cpp/solution.cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/cpp/solution.md
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase6.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase7.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase1.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase2.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase3.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase11test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase4.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase8.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase9.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase5.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/problems/LongestSubstringWithoutRepeatingCharacters/testcases/TestCase10.test
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/problemtest.cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/printer.h
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/CMakeLists.txt
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/typetraits.h
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/problemtest.h
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/parser.h
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/stlincludes.h
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/binder.h
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/main.cpp
-- Installing: /Users/styleys/documents/Portfolio/openleetcode/problem_builds/languages/cpp/solutionwrapper.h
styleys@ThomasdeMacBook-Pro openleetcode % python3 ./problem_builds/openleetcode.py --problem_builds_dir ./problem_builds --language cpp --problem TwoSum -v
Running OpenLeetCode on problem: TwoSum
Building the problem TwoSum in cpp language.
Problem directory: ./problem_builds/problems/TwoSum
Source directory: /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp
Build directory: /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/build
Template source directory: ./problem_builds/languages/cpp
Copying ./problem_builds/languages/cpp/problemtest.cpp to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/problemtest.cpp
Copying ./problem_builds/languages/cpp/printer.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/printer.h
Copying ./problem_builds/languages/cpp/CMakeLists.txt to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/CMakeLists.txt
Copying ./problem_builds/languages/cpp/typetraits.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/typetraits.h
Copying ./problem_builds/languages/cpp/problemtest.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/problemtest.h
Copying ./problem_builds/languages/cpp/parser.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/parser.h
Copying ./problem_builds/languages/cpp/stlincludes.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/stlincludes.h
Copying ./problem_builds/languages/cpp/binder.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/binder.h
Copying ./problem_builds/languages/cpp/main.cpp to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/main.cpp
Copying ./problem_builds/languages/cpp/solutionwrapper.h to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solutionwrapper.h
Extracted function name: twoSum
Writing the function name to /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/solutionfunction.h
The bin directory /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp/bin does not exist. Check the problem_builds_dir and problem arguments.

@mbucko
Copy link
Owner Author

mbucko commented Feb 25, 2024

cmake is supposed to create the bin directory inside /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp

This is the case for Windows. It seems that the bin directory wasn't created in your case. Can you check and find where the executable was built? It should be somewhere in one of the subfolder in /Users/styleys/Documents/Portfolio/openleetcode/problem_builds/problems/TwoSum/cpp.

Anyways, as of now I haven't tested it for iOS because I don't have a Mac. i can try to help you but you might need to do some digging. If you look at openleetcode.py which is the script that builds the solution file and executes the tests. You can try to figure out why what happened there

@mbucko
Copy link
Owner Author

mbucko commented Feb 25, 2024

Actually, I found a small typo in the cmake file. Can refresh your repo and try again?

@ThomasChen0717
Copy link
Contributor

I have found out the error. It stems from the difference in behavior of the operating system's subprocess.run() function in the openleetcode.py file. In macOS, the command should be passed in as command instead of command.split(). I have also made a bit of other changes. Can I commit the changes on another branch so that you could verify the changes and commit if everything looks good?

@mbucko
Copy link
Owner Author

mbucko commented Feb 25, 2024

Yes please do. Also, I am making some big changes to openleetcode.py. I need to standardize how the openleetcode.py will interact with the language-specific binaries. I will document it all so that it's easy to add support for a new language. Should land the changes today.

@ThomasChen0717
Copy link
Contributor

I am unable to push my changes to a new branch I name dev. I got the error: styleys@ThomasdeMacBook-Pro openleetcode % git push -u origin dev
remote: Permission to mbucko/openleetcode.git denied to ThomasChen0717.
fatal: unable to access 'https://github.com/mbucko/openleetcode.git/': The requested URL returned error: 403
I suspect that I would need permissions from your end.

@mbucko
Copy link
Owner Author

mbucko commented Feb 25, 2024

You're trying to push directly to the main repository. However, the typical workflow on GitHub involves working on your own fork of the repository and then submitting a pull request when you're ready to merge your changes.

@ThomasChen0717
Copy link
Contributor

ThomasChen0717 commented Feb 25, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants