{"id":25016499,"url":"https://github.com/rustamkuramshin/leetcode-utils","last_synced_at":"2025-04-24T05:43:57.571Z","repository":{"id":164525531,"uuid":"639997603","full_name":"RustamKuramshin/leetcode-utils","owner":"RustamKuramshin","description":"Super Lightweight Java Library For Debug And Testing LeetCode Problems!","archived":false,"fork":false,"pushed_at":"2023-12-26T04:38:44.000Z","size":32,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-24T05:43:52.647Z","etag":null,"topics":["java","leetcode","leetcode-java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RustamKuramshin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-12T18:09:13.000Z","updated_at":"2025-02-28T19:02:41.000Z","dependencies_parsed_at":"2025-03-30T07:27:18.656Z","dependency_job_id":"9ed9e9f9-c30b-4a5c-8c08-c3c8d10f98c9","html_url":"https://github.com/RustamKuramshin/leetcode-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustamKuramshin%2Fleetcode-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustamKuramshin%2Fleetcode-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustamKuramshin%2Fleetcode-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustamKuramshin%2Fleetcode-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RustamKuramshin","download_url":"https://codeload.github.com/RustamKuramshin/leetcode-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250573299,"owners_count":21452342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","leetcode","leetcode-java"],"created_at":"2025-02-05T09:42:28.120Z","updated_at":"2025-04-24T05:43:57.554Z","avatar_url":"https://github.com/RustamKuramshin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Super Lightweight Java Library For Debug And Testing LeetCode Problems :sunglasses:\n\n## Description\nA java library that will help you solve problems with leetcode. The library is represented by just one java class and does not require any external dependencies other than jdk.\n\n## Features\n* Built-in class of a singly linked list ListNode, supplemented with useful functions such as: printing a list.\n* Built-in class of a doubly linked list Node, supplemented with useful functions such as: printing a list.\n* Built-in binary search class TreeNode, supplemented with useful functions such as: **initialization of a binary tree from a string representation of an integer level-order array**, conversion of a binary tree into an array and vice versa.\n* **A player of test cases for tasks with an integer cache.**\n\nAll classes of leetcode's data structure (Node, ListNode and TreeNode) can be used in your code if you write a solution to the problem in your IDE.\n\n## Usage\nRun the following command in the directory with the code you need:\n```shell\ncd /path/to/your/code/directory\n\ncurl -O https://raw.githubusercontent.com/RustamKuramshin/leetcode-utils/main/src/main/java/leetcode/utils/LeetCodeUtils.java\n```\n\nOr manually copy the contents of the java class file from the following link [https://github.com/RustamKuramshin/leetcode-utils/blob/main/src/main/java/leetcode/utils/LeetCodeUtils.java](https://github.com/RustamKuramshin/leetcode-utils/blob/main/src/main/java/leetcode/utils/LeetCodeUtils.java).\n\n**REMOVE THE JAVA PACKAGE DECLARATION FROM THE JAVA CLASS FILE. OR SPECIFY THE NAME OF THE PACKAGE YOU NEED!**\n\n\nIf necessary, import the class into your java/kotlin code:\n```java\nimport your.package_path.LeetCodeUtils;\n```\nOr just put the java library class next to your classes.\n\nYou can also make a static import of any leetcode data structure class to work with it in your code:\n```java\nimport static your.package_path.LeetCodeUtils.TreeNode;\n\n// ... your code\n\nTreeNode root = TreeNode.ofArrayString(\"[2,1,3,null,4,null,7]\");\n```\n\n## Documentation\n\n### Singly Linked List\n\nClass of a singly linked list:\n```java\nclass ListNode {\n\n    public int val;\n    public ListNode next;\n\n    public ListNode() {\n    }\n\n    public ListNode(int x) {\n        val = x;\n        next = null;\n    }\n    \n    ...\n}\n\n// initialize it: new ListNode()\n```\n#### Print out your linked list (takes into account cyclic (closed) linked lists):\n```java\nlistNode.printListNode()\n// will print [3, 2, 4, 5, 10]\n```\n#### Generate a random singly linked list with the specified parameters:\n```java\nListNode listNode = ListNode.generateRandomListNode(30, 0, 100, ListNode.Order.ASCENDING);\n```\n#### Create a singly linked list from the string representation of the array:\n```java\nListNode list = ListNode.ofArrayString(\"[-10,-3,0,5,9]\");\n```\n\n### Doubly Linked List\n\nDoubly linked list class:\n```java\nclass Node { \n    \n    public Node prev;\n    public Node next;\n\n    public int val;\n    \n    public Node() {\n    }\n\n    public Node(int val) {\n        this.val = val;\n    }\n    \n    ...\n}\n\n// initialize it: new Node()\n```\nPrint out your linked list:\n```java\nnode.printNode()\n// will print [3, 2, 4, 5, 10]\n```\n\n### Binary Tree\n\nBinary Tree class:\n```java\nclass TreeNode {\n\n    public int val;\n    public TreeNode left;\n    public TreeNode right;\n\n    public TreeNode() {\n    }\n\n    public TreeNode(int val) {\n        this.val = val;\n    }\n    \n    ...\n}\n\n// initialize it: new TreeNode()\n```\n#### Get a binary tree from the string representation of the level-order array:\n```java\nTreeNode root = TreeNode.ofArrayString(\"[2,1,3,null,4,null,7]\");\n```\n#### Generate a binary tree of arbitrary size! It is possible to pass parameters specific to binary trees from the LeetCode tasks.\n```java\nTreeNode root = TreeNode.randomBinaryTreeBuilder()\n        .nodesCount(5000) // Required number of binary tree nodes\n        .minNodeVal(-1_000_000_000) // Minimum possible value of a binary tree node\n        .maxNodeVal(1_000_000_000) // Maximum possible value of a binary tree node\n        .mode(TreeNodeMode.BINARY_SEARCH_TREE) // Generation mode\n        .build();\n```\n#### Beautiful binary tree printing\n```java\nroot.printBinaryTree();\n```\nmethod will output:\n```text\n└── 2\n    ├── -2\n    │   ├── -8\n    │   │   ├── -10\n    │   │   └── -5\n    │   └── -1\n    │       ├── -2\n    └── 4\n        ├── 3\n        └── 5\n```\n#### Method of inserting a new node into a binary tree\n```java\nroot.addNode(node);\n```\n#### A method for obtaining the size of a binary tree. Returns the number of nodes.\n```java\nroot.size();\n```\n#### The classic equals() and hashCode() methods, which will help compare two binary trees.\n```java\nroot1.equals(root2);\n```\n\n### Test Case Player For Integer Cache Problems\nA player of test cases for tasks in which you need to work with an integer cache.\nThe cache should follow the following interface:\n```java\ninterface Cache {\n    int get(int key);\n    void put(int key, int value);\n}\n```\nCreate a text file in the resource directory with a sequence of cache methods from the test case:\n```text\n[\"LFUCache\",\"put\",\"put\",\"put\",\"put\",\"put\"]\n```\nCreate a text file in the resource directory with the actual cache method parameters from the test case:\n```text\n[[10],[10,13],[3,17],[6,11],[10,5],[9,10]]\n```\nThe number of methods and the number of sets of actual parameters must match!\nPut these text files in the resource directory.\n\n\nCall the static playTestCase() method of the CacheTestCasePlayer class. This will cause an instance of your cache class to be created and methods with parameters will be called as in the test case with leetcode!\nThe playTestCase() method needs to be passed a reference to your cache class, the path to the file with the sequence of cache methods and the path to the file with the parameters of these methods.\n```java\nCacheTestCasePlayer.playTestCase(LFUCache.class,\"test-cases-data/p460/17/methods.txt\", \"test-cases-data/p460/17/data.txt\");\n```\n\n## Enjoy! :man_technologist:","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustamkuramshin%2Fleetcode-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustamkuramshin%2Fleetcode-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustamkuramshin%2Fleetcode-utils/lists"}