Coder Social home page Coder Social logo

rossmassey / leetcode Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 641 KB

Swift Leetcode solutions

Home Page: https://rossmassey.github.io/leetcode/documentation/leetcode/

License: MIT License

Swift 99.43% Shell 0.57%
leetcode-solutions leetcode-swift swift

leetcode's Introduction

Leetcode

Solutions to leetcode problems implemented in Swift

swift logo

Adding new solution and test case

Run the following interactive script to to generate a blank leetcode solution and test case

swift Scripts/start-new-problem.swift

Documentation

Deploy Documentation

documentation pipeline diagram

Documentation is generated from the markdown in the solution files, with the DocC documentation compiler

Generating

To generate the static documentation in /_site, from the repo folder run:

bash Scripts/generate-docs.sh

To preview the web version, run:

bash Scripts/preview-docs.sh

GitHub Pages is used to host the static content generated by the "Deploy Documentation" workflow

Testing and Linting

Swift Code Validation

swift code validation pipeline diagram

Linting can be ran with the SwiftLint tool:

swiftlint

XCTests can be ran through Xcode or VS Code (with Swift extension), or with:

swift test

Note: Current test cases are just the example inputs/outputs provided by Leetcode, and are not comprehensive

Using Docker

The Swift image for docker can be used if Swift is not installed locally

This command ran from the root of the repo will run the tests for instance:

docker run --rm -it -v "$(pwd):/leetcode" -w /leetcode swift swift test
  • docker run: run a command within a docker container
  • --rm: removes container once it is done
  • --it: runs container in interactive mode (to see console output)
  • -v "$(pwd):/leetcode: mounts current directory to /leetcode inside container
  • -w /leetcode: sets container working directory to /leetcode
  • swift swift test: execute swift test using the swift docker image

leetcode's People

Contributors

rossmassey avatar

Watchers

 avatar

leetcode's Issues

add test case parser for class solutions

solutions where a class is implemented, like LRUCache, have the tests manually done:

e.g.: LRUCacheTests

let lru = LRUCache(2)
lru.put(1,1)
lru.put(2,2)
XCTAssertEqual(lru.get(1), 1)
lru.put(3,3)
XCTAssertEqual(lru.get(2), -1)
lru.put(4,4)
XCTAssertEqual(lru.get(1), -1)
XCTAssertEqual(lru.get(3), 3)
XCTAssertEqual(lru.get(4), 4)

implement generic parser in common package that can be provided a [String:func] dictionary to work with any class solution

leetcode parser example:

Input
["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
Output
[null, null, null, 1, null, -1, null, -1, 3, 4]

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.