• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
2015年12月19日
Leetcode: Summary Ranges
摘要: 这种题就是要写的clean and tidy,好方法: 维护两个指针的方法: 阅读全文
posted @ 2015-12-19 13:33 neverlandly 阅读(267) 评论(0) 推荐(0)
Leetcode: Kth Smallest Element in a BST
摘要: Java Solution 1 - Inorder Traversal We can inorder traverse the tree and get the kth smallest element. Time is O(n). Recursion method: Java Solution 2 阅读全文
posted @ 2015-12-19 13:06 neverlandly 阅读(412) 评论(0) 推荐(0)
Leetcode: Basic Calculator II
摘要: 用Stack来做:时间 O(N) 空间 O(N) 因为乘法和除法不仅要知道下一个数,也要知道上一个数。所以我们用一个栈把上次的数存起来,遇到加减法就直接将数字压入栈中,遇到乘除法就把栈顶拿出来乘或除一下新数,再压回去。最后我们把栈里所有数加起来就行了。 上面这段code可以先用String.repl 阅读全文
posted @ 2015-12-19 12:31 neverlandly 阅读(311) 评论(0) 推荐(0)
Leetcode: Basic Calculator
摘要: https://discuss.leetcode.com/topic/15816/iterative-java-solution-with-stack 第二遍做法:遇到digit直接走到末尾,并且直接利用sign进行计算,这样比较方便 第一遍做法: 阅读全文
posted @ 2015-12-19 06:12 neverlandly 阅读(371) 评论(0) 推荐(0)
Leetcode: Count Complete Tree Nodes
摘要: 递归树高法 复杂度 时间 O(N) 空间 O(1) 思路 完全二叉树的一个性质是,如果左子树最左边的深度,等于右子树最右边的深度,说明这个二叉树是满的,即最后一层也是满的,则以该节点为根的树其节点一共有2^h-1个。如果不等于,则是左子树的节点数,加上右子树的节点数,加上自身这一个。 注意 这里在左 阅读全文
posted @ 2015-12-19 02:30 neverlandly 阅读(333) 评论(0) 推荐(0)
Leetcode: Implement Stack using Queues
摘要: Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. to 阅读全文
posted @ 2015-12-19 01:31 neverlandly 阅读(268) 评论(0) 推荐(0)
Leetcode: Maximal Square
摘要: dp问题,用一个dp[i][j]保存matrix[i][j]作为右下节点的时候的最大矩形的边长 if (matrix[i][j] == '0') dp[i][j] = 0; else dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1]) + 1; 阅读全文
posted @ 2015-12-19 00:47 neverlandly 阅读(347) 评论(0) 推荐(0)
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3