• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
neverlandly
博客园    首页    新随笔    联系   管理    订阅  订阅
2016年11月29日
Leetcode: First Unique Character in a String
摘要: Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may a... 阅读全文
posted @ 2016-11-29 12:24 neverlandly 阅读(312) 评论(0) 推荐(0)
Leetcode: Lexicographical Numbers
摘要: Solution 1: Solution 2: O(N) time, O(1) space The basic idea is to find the next number to add.Take 45 for example: if the current number is 45, the n 阅读全文
posted @ 2016-11-29 11:59 neverlandly 阅读(334) 评论(0) 推荐(0)
Leetcode: Shuffle an Array
摘要: Random random = new Random(); random.nextInt(int i); 阅读全文
posted @ 2016-11-29 10:53 neverlandly 阅读(564) 评论(0) 推荐(0)
Leetcode: Ransom Note
摘要: using one array 阅读全文
posted @ 2016-11-29 06:41 neverlandly 阅读(301) 评论(0) 推荐(0)
Leetcode: Linked List Random Node
摘要: Solution 1: Reservior sampling: (wiki introduction) Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items 阅读全文
posted @ 2016-11-29 06:19 neverlandly 阅读(515) 评论(0) 推荐(0)
Leetcode: Insert Delete GetRandom O(1) - Duplicates allowed
摘要: The idea is to add a set to the hashMap to remember all the locations of a duplicated number. 阅读全文
posted @ 2016-11-29 02:44 neverlandly 阅读(527) 评论(0) 推荐(0)
Leetcode: Insert Delete GetRandom O(1)
摘要: 最先想到是用double LinkedList+Map, 没必要,arraylist+map就够了;另外取random的方法还有,rand.nextInt(int n) returns an integer in the range [0, n) java.util.Random rand = ne 阅读全文
posted @ 2016-11-29 01:27 neverlandly 阅读(535) 评论(0) 推荐(0)
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3