• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅

随笔分类 -  Leetcode

上一页 1 ··· 27 28 29 30 31 32 下一页
Leetcode: Count and Say

摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off ... 阅读全文
posted @ 2014-05-13 12:30 neverlandly 阅读(287) 评论(0) 推荐(0)
Leetcode: Valid Sudoku

摘要:Best Approach: '4' in row 7 is encoded as "(4)7". '4' in column 7 is encoded as "7(4)". '4' in the top-right block is encoded as "0(4)2". 然后在解Sudoku S 阅读全文
posted @ 2014-05-10 06:45 neverlandly 阅读(410) 评论(0) 推荐(0)
Leetcode: Search Insert Position

摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or... 阅读全文
posted @ 2014-05-10 02:33 neverlandly 阅读(243) 评论(0) 推荐(0)
Leetcode: Swap Nodes in Pairs

摘要:1 Given a linked list, swap every two adjacent nodes and return its head.2 3 For example,4 Given 1->2->3->4, you should return the list as 2->1->4->3.... 阅读全文
posted @ 2014-05-10 01:32 neverlandly 阅读(258) 评论(0) 推荐(0)
Leetcode: Remove Nth Node From End of List

摘要:这道题要注意的Corner Case是:如果n比这个LinkedList的size大,那么就需要直接返回Head,如果相等,就把head删掉,返回head.next;基本做的方法呢,还是Runner Technique. 由于有可能head会被删掉,所以最好还是使用一个dummy node,dumm 阅读全文
posted @ 2014-05-09 04:55 neverlandly 阅读(375) 评论(0) 推荐(0)
Leetcode: Valid Parentheses

摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the 阅读全文
posted @ 2014-05-09 04:20 neverlandly 阅读(331) 评论(0) 推荐(0)
Leetcode: Merge Two Sorted Lists

摘要:方法二(推荐方法1): 新的Linkedlist不以任何现有List为依托,维护一个dummmy node和当前节点ListNode cur,把两个list的元素往里面插入作为cur.next,每次不new一个新的ListNode, 而是用已有的。相较于法一最后需要讨论两个list各自没有走完的情况 阅读全文
posted @ 2014-05-09 03:38 neverlandly 阅读(819) 评论(0) 推荐(0)
Leetcode: Longest Common Prefix

摘要:这道题做的不够顺利,许多次通过,但是居然是卡在一个小问题上了,判断strs是否为空,我想当然地就写成了if(strs == null) return null; 报错 java中null表示还没new出对象,就是还没开辟空间;“”表示new出了对象,但是这个对象装的是空字符串。这里显然是要应对str 阅读全文
posted @ 2014-05-08 11:56 neverlandly 阅读(314) 评论(0) 推荐(0)
Leetcode: Roman to Integer

摘要:从右向左,preVal, curVal 1. curVal >= preVal: res+=curVal 2. curVal < preVal: res -= curVal 阅读全文
posted @ 2014-05-08 05:23 neverlandly 阅读(307) 评论(0) 推荐(0)
Leetcode: String to Integer

摘要:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below a... 阅读全文
posted @ 2014-05-08 03:27 neverlandly 阅读(387) 评论(0) 推荐(0)
Leetcode: Palindrome Numbers

摘要:Determine whether an integer is a palindrome. Do this without extra space.尝试用两头分别比较的方法,结果发现无法解决1000021这种问题 1 public class Solution { 2 public bool... 阅读全文
posted @ 2014-05-06 04:06 neverlandly 阅读(323) 评论(0) 推荐(0)
Leetcode: Reverse Integer

摘要:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321一次通过,它的spoiler里面的提示有两个:1. 末尾为0的情况,这个考虑到了2.Did you notice that... 阅读全文
posted @ 2014-05-06 01:06 neverlandly 阅读(509) 评论(0) 推荐(0)
Leetcode: Two Sum

摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex 阅读全文
posted @ 2014-05-06 00:20 neverlandly 阅读(409) 评论(0) 推荐(0)
Leetcode: Path Sum

摘要:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Fo... 阅读全文
posted @ 2014-05-05 12:02 neverlandly 阅读(287) 评论(0) 推荐(0)
Leetcode: Minimum Depth of Binary Tree

摘要:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le... 阅读全文
posted @ 2014-05-04 22:32 neverlandly 阅读(302) 评论(0) 推荐(0)
Leetcode: Balanced Binary Tree

摘要:很锻炼DP/recursive思路的一道题,个人感觉DP/recursive算是比较难写的题目了。这道题解法的巧妙之处在于巧用-1,并且使用临时存储,节省了很多开支。这道题同时也在Career Cup上面出现过 这道题我两次调试通过,第一次错是因为input{}, output false, exp 阅读全文
posted @ 2014-05-03 06:21 neverlandly 阅读(306) 评论(0) 推荐(0)
Leetcode: Maximum Depth of Binary Tree

摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2014-05-03 06:11 neverlandly 阅读(250) 评论(0) 推荐(0)
Leetcode: Same Tree

摘要:Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 1 public... 阅读全文
posted @ 2014-05-03 06:01 neverlandly 阅读(357) 评论(0) 推荐(1)
Leetcode: Remove Duplicates from Sorted List

摘要:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, ... 阅读全文
posted @ 2014-05-03 05:56 neverlandly 阅读(279) 评论(0) 推荐(0)
Leetcode: Plus One

摘要:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at... 阅读全文
posted @ 2014-05-02 05:22 neverlandly 阅读(432) 评论(0) 推荐(0)

上一页 1 ··· 27 28 29 30 31 32 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3