GithubHelp home page GithubHelp logo

leetcode-go's Introduction

LeetCodeProjects

這個repository主要用來存放一些leetcode的解題過程跟心得。IDE使用JetBrains的GoLand,使用的plugin為LeetCode Editor,感謝shuzijun開發這個那麼方便的東西。

設定

這邊的題目都以leetcode.com為主。

下載Plugin

請從preferences->plugins點選marketplace頁籤後尋找leetcode editor安裝。同作者有一個leetcode editor pro的plugin,功能似乎完全相同,只是是付費。如果有條件的朋友可以安裝這個贊助一下作者。

設定Plugin

先從下拉式選單選擇leetcode.com(預設應該是leetcode.cn),填入帳號密碼,語言選擇go,然後建議以下設定

  • TempFilePath: 選擇你leetcode的專案根目錄,如果你是從git clone這個專案的話,就是clone近來的目錄。
  • 點選Custom Template
  • 我個人使用的template會貼在最下面,建議使用這個template。
    • 這個template有提供可以直接執行的test method,通常在ide上該函數左邊都有個▶️可以直接按下去。
    • 有regular test跟table test
    • 可以參考1903_largest-odd-number-in-string_test.go看看如何使用table test

無法使用testify?

某些版本的GoLand預設新專案沒有開啟go mod支援(真的嚇到我了),所以即使go mod init leetcode產出go.mod,然後go get github.com/stretchr/testify ,GoLand仍然無法吃到。

  • 打開Preference
  • 打開Go
  • 點入Go Module
  • 打開Enable Go Module Integration

按照正常流程go get github.com/stretchr/testify 應該就能用了。

Custom Template參考

package leetcode
import "testing"
${question.content}

${question.code}

func Test_$!velocityTool.camelCaseName(${question.titleSlug})(t *testing.T) {

}

func Test_$!velocityTool.camelCaseName(${question.titleSlug})_table(t *testing.T) {
    type args struct {
    }
    
    tests := []struct {
        name string
        args args
        expected interface{}
    }{
        {
        },
    }
    
    for _, test := range tests {
        t.Run(test.name, func(t *testing.T) {
        
        })
    }
    
}

leetcode-go's People

Watchers

Rayer avatar  avatar

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.