【C语言Coding】第十九天
原创
©著作权归作者所有:来自51CTO博客作者小样小响的原创作品,请联系作者获取转载授权,否则将追究法律责任
int finalValueAfterOperations(char ** operations, int operationsSize){
int ans = 0;
for(int i=0;i<operationsSize;i++){
for(int j = 0;j <= 2;j++){
if(operations[i][j] == '+'){
ans++;break;
}
if(operations[i][j] == '-'){
ans--;break;
}
}
}
return ans;
}
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
int kthToLast(struct ListNode* head, int k){
struct ListNode* l = head;
struct ListNode* r = head;
while(k-- > 0) r = r->next;
while(r!=NULL) {
l=l->next;r=r->next;
}
return l->val;
}
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* removeNthFromEnd(struct ListNode* head, int n){
if(head->next == NULL) return NULL;
struct ListNode* O = head;
struct ListNode* L = head;
struct ListNode* R = head;
for(int i=1;i<=n;i++) R=R->next;
if(R == NULL) return head->next;
while(R->next!=NULL){
L=L->next;R=R->next;
}
L->next = L->next->next;
return O;
}
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head){
if(!head) return NULL;
if(head->next == NULL) return head;
struct ListNode* L = head;
struct ListNode* M = L->next;
if(M->next == NULL) {
L->next = NULL;
M->next = L;
return M;
}
struct ListNode* R = M->next;
L->next = NULL;
while(R!=NULL){
M->next = L;
L = M;
M = R;
R = R->next;
}
M->next = L;
return M;
}
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
void deleteNode(struct ListNode* node) {
struct ListNode* O = node;
struct ListNode* L = node;
struct ListNode* R = node->next;
while(R->next!=NULL){
L->val = R->val;
L=L->next;
R=R->next;
}
L->val = R->val;
L->next = NULL;
}