26.删除排序数组中的重复项
java代码:
class Solution {
public int removeDuplicates(int[] nums) {
int a=0;
for(int i=1;i<nums.length;i++){
if(nums[a]!=nums[i])
{
nums[++a]=nums[i];
}
}
return a+1;
}
}
543.二叉树的直径
java代码:
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
int ans;
public int diameterOfBinaryTree(TreeNode root) {
ans =1;
depth(root);
return ans-1;
}
public int depth(TreeNode node){
if(node==null) return 0;
int L=depth(node.left);
int R=depth(node.right);
ans=Math.max(ans,L+R+1);
return Math.max(L,R)+1;
}
}
1071.字符串的最大公因子
java