null

nil vs kNilOptions

戏子无情 提交于 2020-03-17 11:16:56
问题 I find some time ago the enum kNilOptions which is equal to 0. I try to make my code the most readable but I wonder what is best to use when you have methods that take an option parameter, for example : [NSData dataWithContentsOfFile:imageURL.path options:kNilOptions error:&error]; I usually see nil in a lot of code I read but I think kNilOptions would be more accurate. I don't see often (almost never) kNilOptions . Is there a reason for that? Do you think it is ok to use it or is it better

nil vs kNilOptions

房东的猫 提交于 2020-03-17 11:16:39
问题 I find some time ago the enum kNilOptions which is equal to 0. I try to make my code the most readable but I wonder what is best to use when you have methods that take an option parameter, for example : [NSData dataWithContentsOfFile:imageURL.path options:kNilOptions error:&error]; I usually see nil in a lot of code I read but I think kNilOptions would be more accurate. I don't see often (almost never) kNilOptions . Is there a reason for that? Do you think it is ok to use it or is it better

Leetcode_206_Reverse_Linked_List(反转链表)_easy

这一生的挚爱 提交于 2020-03-17 11:16:09
题目: 反转一个单链表。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 解题思路: 1. 迭代法: 从链表的头结点开始遍历链表,依次将节点的next指向节点前一个节点。 关键:要弄清楚prev,curr,next三者之前的关系。 重要部分:因为遍历链表时,要将当前节点curr.next指向当前节点的前一个节点prev,这样就没有办法继续遍历,所以要在这之前,将curr.next的地址值复制一份给ListNode tempNext。 public ListNode reverseList ( ListNode head ) { ListNode prev = null ; ListNode curr = head ; while ( curr != null ) { ListNode nextTemp = curr . next ; curr . next = prev ; prev = curr ; curr = nextTemp ; } return prev ; } 时间复杂度:O(n) 空间复杂度:O(1) 2. 头插法 思想和迭代法一模一样,迭代法里的prev就是newHead.next,都是null,只不过头插法新多了一个ListNode newHead = new ListNode(-1),让它的next =

Can I use NULL as substitution for the value of 0?

这一生的挚爱 提交于 2020-03-12 11:46:09
问题 Am I allowed to use the NULL pointer as replacement for the value of 0 ? Or is there anything wrong about that doing? Like, for example: int i = NULL; as replacement for: int i = 0; As experiment I compiled the following code: #include <stdio.h> int main(void) { int i = NULL; printf("%d",i); return 0; } Output: 0 Indeed it gives me this warning, which is completely correct on its own: warning: initialization makes integer from pointer without a cast [-Wint-conversion] but the result is still

Can I use NULL as substitution for the value of 0?

穿精又带淫゛_ 提交于 2020-03-12 11:43:39
问题 Am I allowed to use the NULL pointer as replacement for the value of 0 ? Or is there anything wrong about that doing? Like, for example: int i = NULL; as replacement for: int i = 0; As experiment I compiled the following code: #include <stdio.h> int main(void) { int i = NULL; printf("%d",i); return 0; } Output: 0 Indeed it gives me this warning, which is completely correct on its own: warning: initialization makes integer from pointer without a cast [-Wint-conversion] but the result is still

Can I use NULL as substitution for the value of 0?

∥☆過路亽.° 提交于 2020-03-12 11:43:29
问题 Am I allowed to use the NULL pointer as replacement for the value of 0 ? Or is there anything wrong about that doing? Like, for example: int i = NULL; as replacement for: int i = 0; As experiment I compiled the following code: #include <stdio.h> int main(void) { int i = NULL; printf("%d",i); return 0; } Output: 0 Indeed it gives me this warning, which is completely correct on its own: warning: initialization makes integer from pointer without a cast [-Wint-conversion] but the result is still

两个链表求第一个公共交点

纵饮孤独 提交于 2020-03-09 19:13:58
输入两个链表,找出它们的第一个公共结点。(注意因为传入数据是链表,所以错误测试数据的提示是用其他方式显示的,保证传入数据是正确的) /** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public class Solution { public ListNode detectCycle ( ListNode head ) { if ( head == null ) { return null ; } ListNode meetNode = meetingNode ( head ) ; if ( meetNode == null ) { //说明无环 return null ; } ListNode fast = head ; ListNode slow = meetNode ; while ( slow != fast ) { slow = slow . next ; fast = fast . next ; } return slow ; } //寻找相遇节点,如果无环,返回null public ListNode meetingNode (

使用DQL语句查询数据

…衆ロ難τιáo~ 提交于 2020-03-09 00:55:00
1.创建表 DROP TABLE IF EXISTS ` tb_emp ` ; CREATE TABLE ` tb_emp ` ( ` emp_id ` int ( 11 ) NOT NULL AUTO_INCREMENT , ` emp_name ` varchar ( 20 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , ` emp_sex ` char ( 3 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , ` dept_id ` int ( 11 ) NULL DEFAULT NULL , ` salary ` double ( 5 , 1 ) NULL DEFAULT 4000.0 , ` emp_mail ` varchar ( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'default@mail.com' , PRIMARY KEY ( ` emp_id ` ) USING BTREE , INDEX ` dept_id ` ( ` dept_id ` ) USING BTREE , CONSTRAINT ` tb_emp_ibfk_1 ` FOREIGN KEY

如何实现链表的逆序

不想你离开。 提交于 2020-03-09 00:32:28
package com.example.lib; public class LianBiao1 { public static void main(String[] args) { LNode head=new LNode(); LNode next=null; for(int i=1;i<=7;i++){ LNode cur=new LNode(); cur.data=i; if(head.next==null){ head.next=cur; next=cur; }else { next.next=cur; next=cur; } } next.next=null; Reverse(head); printNode(head); } public static void printNode(LNode head){ StringBuffer buffer=new StringBuffer(); LNode cur=head.next; while (cur!=null){ buffer.append(" "+cur.data); cur=cur.next; } System.out.println(buffer.toString()+"\n"); } public static void Reverse(LNode head){ //head-> 1 ->2 ->3 -> 4

【leetcode 刷题日记】07-合并两个有序链表(C++)

假如想象 提交于 2020-03-08 02:59:49
合并两个有序链表 题目 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 思路 创建一个虚拟头节点,用指针cur指向头节点,然后和l1、l2比较,cur->next指向其中较小的一个。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public : ListNode * mergeTwoLists ( ListNode * l1 , ListNode * l2 ) { if ( l1 == NULL && l2 == NULL ) return NULL ; ListNode * dummyHead = new ListNode ( 0 ) ; ListNode * cur = dummyHead ; while ( l1 != NULL || l2 != NULL ) { if ( l1 == NULL || ( l2 != NULL && ( l1 - > val >= l2 - >