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






richardcpp

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

2013年5月2日

bit-manipulation(1)
摘要: You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M becomes a substring of N located at i and starting at j).EXAMPLE:Input: N = 10000000000, M = 10101, i = 2, j = 6Output: N = 10001010100solution中是有错误的假设n的 阅读全文
posted @ 2013-05-02 20:50 richardcpp 阅读(263) 评论(0) 推荐(0)
 
Linked Lists
摘要: 创建一个链表:NOTE: When you’re discussing a linked list in an interview, make sure to understand whether it is a single linked list or a doubly linked list.1 class Node {2 Node next = null;3 int data;4 public Node(int d) { data = d; }5 void appendToTail(int d) {6 Node end = new Node(d);7 Node n = this;8 w 阅读全文
posted @ 2013-05-02 15:25 richardcpp 阅读(357) 评论(0) 推荐(0)
 
判断链表是否存在环,找出环的入口
摘要: 一、判断链表是否存在环,办法为:设置两个指针(fast, slow),初始值都指向头,slow每次前进一步,fast每次前进二步,如果链表存在环,则fast必定先进入环,而slow后进入环,两个指针必定相遇。(当然,fast先行头到尾部为NULL,则为无环链表)程序如下:bool IsExitsLoop(slist *head) { slist *slow = head, *fast = head; while ( fast && fast->next ) { slow = slow->next; fast = fast->next->next; if 阅读全文
posted @ 2013-05-02 15:08 richardcpp 阅读(329) 评论(0) 推荐(0)