上一页 1 2 3 4 5 6 ··· 8 下一页
摘要: 不禁让我想起了计算机是怎样进行除法运算的,单独考虑溢出以及边界情况,单独考虑符号,其他过程和我们小学除法是一模一样的:左移除数(十进制就是扩大十倍,二进制扩大两倍),直到正好比被除数小,一边累加商(在我的代码里就是33行)一边减小被除数,直到被除数不能减小,右移除数,重复上述过程。 阅读全文
posted @ 2019-10-20 08:23 dodoBehind 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 计算机数字的储存分为:1、无符号数,2、有符号数 无符号数:只能表示正数。每一位数都代表2的幂次方。只有地址用无符号数,无符号数不进行算术操作,之进行指针的加减。地址并不会造成错误的结果,而是产生一个空操作(气泡),所以无符号数不考虑溢出。 有符号数:可以表示负数。有符号数有三种表示法:1、原码,2 阅读全文
posted @ 2019-10-08 14:08 dodoBehind 阅读(647) 评论(0) 推荐(0) 编辑
摘要: 1 public int removeElement(int[] nums, int val) { 2 int last = nums.length - 1; 3 for (int i = 0; i <= last && last >= 0; i++) { 4 while (last >= 0 && nums[last] == val) last--; 5 if (last >= 0 && i < 阅读全文
posted @ 2019-09-30 22:14 dodoBehind 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 1 public class HeapSort { 2 public static void main(String[] args) { 3 int[] a = new int[]{6, 2, 8, 3, 5, 1, 8, 6, 54, 64, -1, 2, 4, 4, 67}; 4 heapSort(a); 5 System.out.println(); 6 } 7 8 static void 阅读全文
posted @ 2019-09-26 09:37 dodoBehind 阅读(147) 评论(0) 推荐(0) 编辑
摘要: https://www.nowcoder.com/practice/b736e784e3e34731af99065031301bca 构造函数:new ArrayList(al)把al的所有值复制到 new ArrayList()里,并且 new ArrayList()的值不会随着al的改变而改变。 阅读全文
posted @ 2019-09-25 23:29 dodoBehind 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 复用left[],【时间击败73.33%】——》【时间击败99.72%】 【内存击败36.17%】——》【内存击败94.23%】 dfs(r)返回值=new long[]{包括r节点的子树所有节点的最小值,包括r节点的子树所有节点的最大值} 阅读全文
posted @ 2019-09-25 17:03 dodoBehind 阅读(202) 评论(0) 推荐(0) 编辑
摘要: public List<Integer> inorderTraversal(TreeNode root) { ArrayList<Integer>al=new ArrayList<>(); if (root==null)return al; al.addAll(inorderTraversal(root.left)); al.add(root.val); al.addAll(inorderTrav 阅读全文
posted @ 2019-09-25 11:53 dodoBehind 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 1 public TreeNode pruneTree(TreeNode root) { 2 dfs(root,null,-1); 3 return root; 4 } 5 6 public void dfs(TreeNode cur, TreeNode fa, int left) { 7 if (cur == null) return; 8 if (check(cur)) { 9 if (lef 阅读全文
posted @ 2019-09-25 11:35 dodoBehind 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 1 public List> printTree(TreeNode root) { 2 ArrayList> al = new ArrayList(); 3 if (root == null) return al; 4 if (root.left == null && root.right == null) { 5 ... 阅读全文
posted @ 2019-09-25 11:00 dodoBehind 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 数组替代队列,从超时到击败70%,用tree[0]替代new一个新的ArrayList,上升10% 思想是遍历一遍,删除度为1的节点,答案只可能为1或2 阅读全文
posted @ 2019-09-25 09:58 dodoBehind 阅读(184) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 8 下一页