
java
wcxdell
研究僧一名
展开
-
leetcode 292 Nim Game JAVA
本来因为在搞ios所以想用c++刷题来着,但是由于实验室要搞java项目,还是用java来练练手吧,面试的时候用java写代码也比较方便。iOS虽然由于回到实验室了,不能再继续实习,所以决定在空闲时间把之前的代码整理一下开源一些控件出来。不说废话了,看代码。public class Solution { public boolean canWinNim(int n) {原创 2016-03-02 09:51:51 · 304 阅读 · 0 评论 -
LeetCode 258 Add Digits java
下面是标准解法,循环+递归。public class Solution { public int addDigits(int num) { int tmp = 0; while (true){ tmp += num % 10; num = num / 10; if (nu原创 2016-03-02 10:14:39 · 365 阅读 · 0 评论 -
LeetCode 104 Maximum Depth of Binary Tree JAVA
代码如下,递归。public class Solution { public int maxDepth(TreeNode root) { if (root == null) return 0; int left = maxDepth(root.left); int right = maxDepth(root.right);原创 2016-03-02 14:35:25 · 362 阅读 · 0 评论 -
LeetCode 226 Invert Binary Tree JAVA
这个比较逗,二叉树转置。有一个故事,自己百度吧。代码如下:public class Solution { public TreeNode invertTree(TreeNode root) { if (root == null) return null; TreeNode tmp = invertTree(root.left);原创 2016-03-02 14:43:52 · 465 阅读 · 0 评论