Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/leetcode/problems_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ var problemStatus = map[int]bool{
344: true,
345: true,
350: true,
367: true,
371: true,
383: true,
387: true,
Expand Down
7 changes: 7 additions & 0 deletions problems/valid-perfect-square/valid_perfect_square.go
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
package problem367

func isPerfectSquare(num int) bool {
for i := 1; num > 0; i += 2 {
num -= i
}
return num == 0
}
38 changes: 38 additions & 0 deletions problems/valid-perfect-square/valid_perfect_square_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
package problem367

import "testing"

type testType struct {
in int
want bool
}

func TestIsPerfectSquare(t *testing.T) {
tests := [...]testType{
{
in: 16,
want: true,
},
{
in: 14,
want: false,
},
{
in: 0,
want: true,
},
{
in: 1,
want: true,
},
{
in: 3,
want: false,
},
}
for _, tt := range tests {
got := isPerfectSquare(tt.in)
if got != tt.want {
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
}
}
}