Skip to content

Commit

Permalink
go implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed Apr 28, 2019
1 parent a578ef7 commit 8a4f57f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 367. Valid Perfect Square/valid_perfect_square.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package problem367

func isPerfectSquare(num int) bool {
if num == 1 {
return true
}
left, right := 0, num
var mid int
for left <= right {
mid = (left + right) / 2
if mid*mid == num {
return true
} else if mid*mid < num {
left = mid + 1
} else {
right = mid - 1
}
}
return false
}

0 comments on commit 8a4f57f

Please sign in to comment.